@ -0,0 +1,38 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
require_once "../inc/global.inc.php"; |
||||
echo "<pre>". |
||||
get_lang('SummationPlus')."\n". |
||||
get_lang('SubstractionMinus')."\n". |
||||
get_lang('MultiplicationStar')."\n". |
||||
get_lang('DivisionSlash')."\n". |
||||
get_lang('ExponentiationCircumflex')."\n". |
||||
"\n". |
||||
get_lang('SquareRootSqrt')."\n". |
||||
get_lang('AbsoluteValueAbs')."\n". |
||||
get_lang('NaturalLogarithmLn')."\n". |
||||
get_lang('LogarithmLog')."\n". |
||||
get_lang('ENumberE')."\n". |
||||
get_lang('PiNumberPi')."\n". |
||||
"\n". |
||||
get_lang('SineSin')."\n". |
||||
get_lang('HyperbolicSineSinh')."\n". |
||||
get_lang('ArcsineArcsin')."\n". |
||||
get_lang('InverseSineAsin')."\n". |
||||
get_lang('HyperbolicArcsineArcsinh')."\n". |
||||
get_lang('InverseHyperbolicSineAsinh')."\n". |
||||
"\n". |
||||
get_lang('CosineCos')."\n". |
||||
get_lang('HyperbolicCosineCosh')."\n". |
||||
get_lang('ArccosineArccos')."\n". |
||||
get_lang('InverseCosineAcos')."\n". |
||||
get_lang('HyperbolicArccosineArccosh')."\n". |
||||
get_lang('InverseHyperbolicCosineAcosh')."\n". |
||||
"\n". |
||||
get_lang('TangentTan')."\n". |
||||
get_lang('HyperbolicTangentTanh')."\n". |
||||
get_lang('ArctangentArctan')."\n". |
||||
get_lang('InverseTangentAtan')."\n". |
||||
get_lang('HyperbolicArctangentArctanh')."\n". |
||||
get_lang('InverseHyperbolicTangentAtanh'). |
||||
"</pre>"; |
@ -0,0 +1,128 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Class for manage the messages web service |
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> |
||||
* @package chamilo.webservices.messages |
||||
*/ |
||||
class MessagesWebService extends WebService |
||||
{ |
||||
|
||||
const SERVICE_NAME = 'MsgREST'; |
||||
|
||||
/** |
||||
* Generate the api key for a user |
||||
* @param int $userId The user id |
||||
* @return string The api key |
||||
*/ |
||||
public function generateApiKey($userId) |
||||
{ |
||||
$apiKey = UserManager::get_api_keys($userId, self::SERVICE_NAME); |
||||
|
||||
if (empty($apiKey)) { |
||||
UserManager::add_api_key($userId, self::SERVICE_NAME); |
||||
|
||||
$apiKey = UserManager::get_api_keys($userId, self::SERVICE_NAME); |
||||
} |
||||
|
||||
return current($apiKey); |
||||
} |
||||
|
||||
/** |
||||
* Get the user api key |
||||
* @param string $username The user name |
||||
* @return string The api key |
||||
*/ |
||||
public function getApiKey($username) |
||||
{ |
||||
$userInfo = api_get_user_info_from_username($username); |
||||
$userId = $userInfo['user_id']; |
||||
|
||||
if ($this->apiKey !== null) { |
||||
return $this->apiKey; |
||||
} else { |
||||
$this->apiKey = $this->generateApiKey($userId); |
||||
|
||||
return $this->apiKey; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Check if the api is valid for a user |
||||
* @param string $username The username |
||||
* @param string $apiKeyToValidate The api key |
||||
* @return boolean Whether the api belongs to the user return true. Otherwise return false |
||||
*/ |
||||
public static function isValidApiKey($username, $apiKeyToValidate) |
||||
{ |
||||
$userInfo = api_get_user_info_from_username($username); |
||||
$userId = $userInfo['user_id']; |
||||
|
||||
$apiKeys = UserManager::get_api_keys($userId, self::SERVICE_NAME); |
||||
|
||||
if (!empty($apiKeys)) { |
||||
$apiKey = current($apiKeys); |
||||
|
||||
if ($apiKey == $apiKeyToValidate) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* Get the count of new messages for a user |
||||
* @param string $username The username |
||||
* @param int $lastId The id of the last received message |
||||
* @return int The count fo new messages |
||||
*/ |
||||
public function countNewMessages($username, $lastId = 0) |
||||
{ |
||||
$userInfo = api_get_user_info_from_username($username); |
||||
$userId = $userInfo['user_id']; |
||||
|
||||
return MessageManager::countMessagesFromLastReceivedMessage($userId, $lastId); |
||||
} |
||||
|
||||
/** |
||||
* Get the list of new messages for a user |
||||
* @param string $username The username |
||||
* @param int $lastId The id of the last received message |
||||
* @return array the new message list |
||||
*/ |
||||
public function getNewMessages($username, $lastId = 0) |
||||
{ |
||||
$messages = array(); |
||||
|
||||
$userInfo = api_get_user_info_from_username($username); |
||||
$userId = $userInfo['user_id']; |
||||
|
||||
$lastMessages = MessageManager::getMessagesFromLastReceivedMessage($userId, $lastId); |
||||
|
||||
foreach ($lastMessages as $message) { |
||||
$hasAttachments = MessageManager::hasAttachments($message['id']); |
||||
|
||||
$messages[] = array( |
||||
'id' => $message['id'], |
||||
'title' => $message['title'], |
||||
'sender' => array( |
||||
'id' => $message['user_id'], |
||||
'lastname' => $message['lastname'], |
||||
'firstname' => $message['firstname'], |
||||
'completeName' => api_get_person_name($message['firstname'], $message['lastname']), |
||||
), |
||||
'content' => $message['content'], |
||||
'hasAttachments' => $hasAttachments, |
||||
'platform' => array( |
||||
'website' => api_get_path(WEB_PATH), |
||||
'messagingTool' => api_get_path(WEB_PATH) . 'main/messages/inbox.php' |
||||
) |
||||
); |
||||
} |
||||
|
||||
return $messages; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,72 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* Base class for Web Services |
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> |
||||
* @package chamilo.webservices |
||||
*/ |
||||
abstract class WebService |
||||
{ |
||||
|
||||
protected $apiKey; |
||||
|
||||
/** |
||||
* Class constructor |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
$this->apiKey = null; |
||||
} |
||||
|
||||
/** |
||||
* Set the api key |
||||
* @param string $apiKey The api key |
||||
*/ |
||||
public function setApiKey($apiKey) |
||||
{ |
||||
$this->apiKey = $apiKey; |
||||
} |
||||
|
||||
/** |
||||
* @abstract |
||||
*/ |
||||
abstract public function getApiKey($username); |
||||
|
||||
/** |
||||
* Check whether the username and password are valid |
||||
* @param string $username The username |
||||
* @param string $password the password |
||||
* @return boolean Whether the password belongs to the username return true. Otherwise return false |
||||
*/ |
||||
public static function isValidUser($username, $password) |
||||
{ |
||||
if (empty($username) || empty($password)) { |
||||
return false; |
||||
} |
||||
|
||||
$userTable = Database::get_main_table(TABLE_MAIN_USER); |
||||
|
||||
$whereConditions = array( |
||||
"username = '?' " => $username, |
||||
"AND password = '?'" => sha1($password) |
||||
); |
||||
|
||||
$conditions = array( |
||||
'where' => $whereConditions |
||||
); |
||||
|
||||
$table = Database::select('count(1) as qty', $userTable, $conditions); |
||||
|
||||
if ($table != false) { |
||||
$row = current($table); |
||||
|
||||
if ($row['qty'] > 0) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
} |
After Width: | Height: | Size: 264 KiB |
After Width: | Height: | Size: 278 KiB |
After Width: | Height: | Size: 261 KiB |
After Width: | Height: | Size: 260 KiB |
After Width: | Height: | Size: 261 KiB |
After Width: | Height: | Size: 262 KiB |
After Width: | Height: | Size: 3.0 KiB |
@ -0,0 +1,79 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Controller for REST request |
||||
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com> |
||||
* @package chamilo.plugin.tour |
||||
*/ |
||||
/* Require libs and classes */ |
||||
require_once '../main/inc/global.inc.php'; |
||||
|
||||
/* Manage actions */ |
||||
$json = array(); |
||||
|
||||
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'nothing'; |
||||
$username = isset($_POST['username']) ? Security::remove_XSS($_POST['username']) : null; |
||||
$apiKey = isset($_POST['api_key']) ? Security::remove_XSS($_POST['api_key']) : null; |
||||
|
||||
switch ($action) { |
||||
case 'loginNewMessages': |
||||
$password = isset($_POST['password']) ? Security::remove_XSS($_POST['password']) : null; |
||||
|
||||
if (MessagesWebService::isValidUser($username, $password)) { |
||||
$webService = new MessagesWebService(); |
||||
|
||||
$apiKey = $webService->getApiKey($username); |
||||
|
||||
$json = array( |
||||
'status' => true, |
||||
'apiKey' => $apiKey |
||||
); |
||||
} else { |
||||
$json = array( |
||||
'status' => false |
||||
); |
||||
} |
||||
break; |
||||
case 'countNewMessages': |
||||
if (MessagesWebService::isValidApiKey($username, $apiKey)) { |
||||
$webService = new MessagesWebService(); |
||||
$webService->setApiKey($apiKey); |
||||
|
||||
$lastId = isset($_POST['last']) ? $_POST['last'] : 0; |
||||
|
||||
$count = $webService->countNewMessages($username, $lastId); |
||||
|
||||
$json = array( |
||||
'status' => true, |
||||
'count' => $count |
||||
); |
||||
} else { |
||||
$json = array( |
||||
'status' => false |
||||
); |
||||
} |
||||
break; |
||||
case 'getNewMessages': |
||||
if (MessagesWebService::isValidApiKey($username, $apiKey)) { |
||||
$webService = new MessagesWebService(); |
||||
$webService->setApiKey($apiKey); |
||||
|
||||
$lastId = isset($_POST['last']) ? $_POST['last'] : 0; |
||||
|
||||
$messages = $webService->getNewMessages($username, $lastId); |
||||
|
||||
$json = array( |
||||
'status' => true, |
||||
'messages' => $messages |
||||
); |
||||
} else { |
||||
$json = array( |
||||
'status' => false |
||||
); |
||||
} |
||||
break; |
||||
default: |
||||
} |
||||
|
||||
/* View */ |
||||
echo json_encode($json); |