Added CM-webservices developed by Marco Sousa and team to handle Chamilo Android application calls

skala
Yannick Warnier 14 years ago
parent f6a51da538
commit d58b18f8c8
  1. 116
      main/webservices/cm_soap.php
  2. 48
      main/webservices/cm_soap_announcements.php
  3. 291
      main/webservices/cm_soap_course.php
  4. 45
      main/webservices/cm_soap_courses.php
  5. 145
      main/webservices/cm_soap_forum.php
  6. 113
      main/webservices/cm_soap_inbox.php
  7. 102
      main/webservices/cm_soap_user.php
  8. 293
      main/webservices/cm_webservice.php
  9. 187
      main/webservices/cm_webservice_announcements.php
  10. 527
      main/webservices/cm_webservice_course.php
  11. 56
      main/webservices/cm_webservice_courses.php
  12. 293
      main/webservices/cm_webservice_forum.php
  13. 228
      main/webservices/cm_webservice_inbox.php
  14. 179
      main/webservices/cm_webservice_user.php

@ -0,0 +1,116 @@
<?php
require_once '../inc/global.inc.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'nusoap/nusoap.php';
/**
* SOAP error handler. Handles an error sending a SOAP fault
*/
class WSCMSoapErrorHandler implements WSCMErrorHandler {
/**
* Handles the error by sending a SOAP fault through the server
*
* @param WSError Error to handle
*/
public function handle($error) {
$server = WSCMSoapServer::singleton();
$server->fault(strval($error->code), $error->message);
}
}
/**
* SOAP server wrapper implementing a Singleton
*/
class WSCMSoapServer {
/**
* SOAP server instance
*
* @var soap_server
*/
private static $_instance;
/**
* Private constructor
*/
private function __construct() {
}
/**
* Singleton method
*/
public static function singleton() {
if(!isset(self::$_instance)) {
self::$_instance = new soap_server();
// Set the error handler
WSCMError::setErrorHandler(new WSCMSoapErrorHandler());
// Configure the service
self::$_instance->configureWSDL('WSCMService', 'urn:WSCMService');
}
return self::$_instance;
}
}
$s = WSCMSoapServer::singleton();
$s->wsdl->addComplexType(
'result',
'complexType',
'struct',
'all',
'',
array(
'code' => array('name' => 'code', 'type' => 'xsd:int'),
'message' => array('name' => 'message', 'type' => 'xsd:string')
)
);
$s->wsdl->addComplexType(
'extra_field',
'complexType',
'struct',
'all',
'',
array(
'field_name' => array('name' => 'field_name', 'type' => 'xsd:string'),
'field_value' => array('name' => 'field_value', 'type' => 'xsd:string')
)
);
$s->register(
'WSCM.verifyUserPass',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
),
array('return' => 'xsd:string')
);
$s->register(
'WSCM.encryptPass',
array('password' => 'xsd:string'),
array('return' => 'xsd:string')
);
$s->register(
'WSCM.test',
array(),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
''
);
require_once(dirname(__FILE__).'/cm_soap_inbox.php');
require_once(dirname(__FILE__).'/cm_soap_user.php');
require_once(dirname(__FILE__).'/cm_soap_courses.php');
require_once(dirname(__FILE__).'/cm_soap_announcements.php');
require_once(dirname(__FILE__).'/cm_soap_forum.php');
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$s->service($HTTP_RAW_POST_DATA);

@ -0,0 +1,48 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_announcements.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->register(
'WSCMAnnouncements.get_announcements_id',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID dos anuncios visiveis a um usuario de uma disciplina.'
);
$s->register(
'WSCMAnnouncements.get_announcement_data',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'announcement_id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o conteudo do campo informado de um anuncio de chave ID. Campos retornaveis: sender, date, title e content'
);

@ -0,0 +1,291 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_course.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->wsdl->addComplexType(
'course_id',
'complexType',
'struct',
'all',
'',
array(
'course_id_field_name' => array('name' => 'course_id_field_name', 'type' => 'xsd:string'),
'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string')
)
);
$s->wsdl->addComplexType(
'course_result',
'complexType',
'struct',
'all',
'',
array(
'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string'),
'result' => array('name' => 'result', 'type' => 'tns:result')
)
);
$s->wsdl->addComplexType(
'course_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_result[]')),
'tns:course_result'
);
$s->register(
'WSCMCourse.DeleteCourse',
array('secret_key' => 'xsd:string', 'course_id_field_name' => 'xsd:string', 'course_id_value' => 'xsd:string')
);
$s->register(
'WSCMCourse.DeleteCourses',
array('secret_key' => 'xsd:string', 'courses' => 'tns:course_id[]'),
array('return' => 'tns:course_result_array')
);
$s->register(
'WSCMCourse.CreateCourse',
array(
'secret_key' => 'xsd:string',
'title' => 'xsd:string',
'category_code' => 'xsd:string',
'wanted_code' => 'xsd:string',
'tutor_name' => 'xsd:string',
'course_admin_user_id_field_name' => 'xsd:string',
'course_admin_user_id_value' => 'xsd:string',
'language' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'extras' => 'tns:extra_field[]'
),
array('return' => 'xsd:int')
);
$s->wsdl->addComplexType(
'course_create',
'complexType',
'struct',
'all',
'',
array(
'title' => array('name' => 'title', 'type' => 'xsd:string'),
'category_code' => array('name' => 'category_code', 'type' => 'xsd:string'),
'wanted_code' => array('name' => 'wanted_code', 'type' => 'xsd:int'),
'tutor_name' => array('name' => 'tutor_name', 'type' => 'xsd:string'),
'course_admin_user_id_field_name' => array('name' => 'course_admin_user_id_field_name', 'type' => 'xsd:string'),
'course_admin_user_id_value' => array('name' => 'course_admin_user_id_value', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'course_id_field_name' => array('name' => 'course_id_field_name', 'type' => 'xsd:string'),
'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string'),
'extras' => array('name' => 'extras', 'type' => 'tns:extra_field[]')
)
);
$s->wsdl->addComplexType(
'course_create_result',
'complexType',
'struct',
'all',
'',
array(
'course_id_value' => array('name' => 'course_id_value', 'type' => 'xsd:string'),
'course_id_generated' => array('name' => 'course_id_generated', 'type' => 'xsd:int'),
'result' => array('name' => 'result', 'type' => 'tns:result')
)
);
$s->wsdl->addComplexType(
'course_create_result_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_create_result[]')),
'tns:course_create_result'
);
$s->register(
'WSCMCourse.CreateCourses',
array(
'secret_key' => 'xsd:string',
'courses' => 'tns:course_create[]'
),
array('return' => 'tns:course_create_result_array')
);
$s->register(
'WSCMCourse.EditCourse',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'title' => 'xsd:string',
'category_code' => 'xsd:string',
'department_name' => 'xsd:string',
'department_url' => 'xsd:string',
'language' => 'xsd:string',
'visibility' => 'xsd:int',
'subscribe' => 'xsd:int',
'unsubscribe' => 'xsd:int',
'visual_code' => 'xsd:string',
'extras' => 'tns:extra_field[]'
)
);
$s->wsdl->addComplexType(
'course',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:int'),
'code' => array('name' => 'code', 'type' => 'xsd:string'),
'title' => array('name' => 'title', 'type' => 'xsd:string'),
'language' => array('name' => 'language', 'type' => 'xsd:string'),
'visibility' => array('name' => 'visibility', 'type' => 'xsd:int'),
'category_name' => array('name' => 'category_name', 'type' => 'xsd:string'),
'number_students' => array('name' => 'number_students', 'type' => 'xsd:int'),
'external_course_id' => array('name' => 'external_course_id', 'type' => 'xsd:string'),
)
);
$s->wsdl->addComplexType(
'course_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course[]')),
'tns:course'
);
$s->register(
'WSCMCourse.ListCourses',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string'
),
array('return' => 'tns:course_array')
);
$s->register(
'WSCMCourse.SubscribeUserToCourse',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string',
'status' => 'xsd:int'
)
);
$s->register(
'WSCMCourse.UnsubscribeUserFromCourse',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'user_id_field_name' => 'xsd:string',
'user_id_value' => 'xsd:string'
)
);
$s->wsdl->addComplexType(
'course_description',
'complexType',
'struct',
'all',
'',
array(
'course_desc_id' => array('name' => 'course_desc_id', 'type' => 'xsd:int'),
'course_desc_title' => array('name' => 'course_desc_title', 'type' => 'xsd:string'),
'course_desc_content' => array('name' => 'course_desc_content', 'type' => 'xsd:string')
)
);
$s->wsdl->addComplexType(
'course_description_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:course_description[]')),
'tns:course_description'
);
$s->register(
'WSCMCourse.GetCourseDescriptions',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string'
),
array('return' => 'tns:course_description_array')
);
$s->register(
'WSCMCourse.EditCourseDescription',
array(
'secret_key' => 'xsd:string',
'course_id_field_name' => 'xsd:string',
'course_id_value' => 'xsd:string',
'course_desc_id' => 'xsd:int',
'course_desc_title' => 'xsd:string',
'course_desc_content' => 'xsd:string'
)
);
$s->register(
'WSCMCourse.unreadMessage',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna a quantidade de mensagens nao lidas na caixa de entrada do usuario.'
);
$s->register(
'WSCMCourse.getIdMessage',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID das mensagens.'
);
$s->register(
'WSCMCourse.nada',
array('username' => 'xsd:string', 'password' => 'xsd:string'),
array('return' => 'xsd:string')
);

@ -0,0 +1,45 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_courses.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->register(
'WSCMCourses.get_courses_code',
array(
'username' => 'xsd:string',
'password' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o CODE dos cursos do username.'
);
$s->register(
'WSCMCourses.get_course_title',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o titulo/nome do curso de course_code informado'
);

@ -0,0 +1,145 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_forum.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->register(
'WSCMForum.get_foruns_id',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID dos foruns de uma disciplina.'
);
$s->register(
'WSCMForum.get_forum_title',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'forum_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o valor do titulo de um forum_id.'
);
$s->register(
'WSCMForum.get_forum_threads_id',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'forum_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID das threads de um forum_id.'
);
$s->register(
'WSCMForum.get_forum_thread_data',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'thread_id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o campo field de um thread_id. Campos possiveis: title, date, sender, sender_name.'
);
$s->register(
'WSCMForum.get_forum_thread_title',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'thread_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o campo title de uma thread_id.'
);
$s->register(
'WSCMForum.get_posts_id',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'thread_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID dos posts de uma thread.'
);
$s->register(
'WSCMForum.get_post_data',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'post_id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o campo field de um post_id. Campos possiveis: title, text, date, sender ou sender_name.'
);
$s->register(
'WSCMForum.send_post',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'course_code' => 'xsd:string',
'forum_id' => 'xsd:string',
'thread_id' => 'xsd:string',
'title' => 'xsd:string',
'content' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Envia um novo post ao forum_id.'
);

@ -0,0 +1,113 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_inbox.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->register(
'WSCMInbox.unreadMessage',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna a quantidade de mensagens nao lidas na caixa de entrada do usuario.'
);
$s->register(
'WSCMInbox.get_message_id',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'from' => 'xsd:string',
'number_of_items' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID das mensagens de entrada entre o intervalo de from até number_of_items.'
);
$s->register(
'WSCMInbox.get_message_data',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o conteudo do campo informado em field da mensagem de entrada id. Os campos retornados sao: sender, title, date, status e content.'
);
$s->register(
'WSCMInbox.get_message_id_sent',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'from' => 'xsd:string',
'number_of_items' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o ID das mensagens de saida entre o intervalo de from até number_of_items.'
);
$s->register(
'WSCMInbox.get_message_data_sent',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o conteudo do campo informado em field da mensagem de saida id. Os campos retornados sao: sender, title, date, status e content.'
);
$s->register(
'WSCMInbox.message_send',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'receiver_user_id' => 'xsd:string',
'subject' => 'xsd:string',
'content' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Envia uma mensagem via rede social. Retorna o id da mensagem enviada.'
);

@ -0,0 +1,102 @@
<?php
require_once(dirname(__FILE__).'/cm_webservice_user.php');
require_once(dirname(__FILE__).'/cm_soap.php');
/**
* Configures the WSCourse SOAP service
*/
$s = WSCMSoapServer::singleton();
$s->register(
'WSCMUser.find_id_user',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'name' => 'xsd:string',
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o id de um usuario que contenha o parametro \'nome\' nos campos nome, sobrenome ou email (ordenado por nome).'
);
$s->register(
'WSCMUser.get_user_name',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'id' => 'xsd:string',
'field' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o primeiro, ultimo ou os dois nomes de um usuarios. No campo field deve ser informado firstname, lastname, bothfl (para fistname lastname) ou bothlf (para lastname firstname)'
);
$s->register(
'WSCMUser.get_link_user_picture',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Retorna o link para a imagem do perfil do usuario.'
);
$s->register(
'WSCMUser.send_invitation',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'userfriend_id' => 'xsd:string',
'content_message' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Envia um convite para estabelecer amizado no portal. O campo userfriend_id o id do possivel amigo e o campo content_message e a mensagem de solicitacao.'
);
$s->register(
'WSCMUser.accept_friend',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'userfriend_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Aceita o convite realizado pelo userfriend_id.'
);
$s->register(
'WSCMUser.denied_invitation',
array(
'username' => 'xsd:string',
'password' => 'xsd:string',
'userfriend_id' => 'xsd:string'
),
array('return' => 'xsd:string'),
'urn:WSCMService',
'',
'',
'',
'Recusa o contive de amizade feito pelo usuario userfriend_id.'
);
?>

@ -0,0 +1,293 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'course.lib.php';
/**
* Error returned by one of the methods of the web service. Contains an error code and an error message
*/
class WSCMError {
/**
* Error handler. This needs to be a class that implements the interface WSErrorHandler
*
* @var WSErrorHandler
*/
protected static $_handler;
/**
* Error code
*
* @var int
*/
public $code;
/**
* Error message
*
* @var string
*/
public $message;
/**
* Constructor
*
* @param int Error code
* @param string Error message
*/
public function __construct($code, $message) {
$this->code = $code;
$this->message = $message;
}
/**
* Sets the error handler
*
* @param WSErrorHandler Error handler
*/
public static function setErrorHandler($handler) {
if($handler instanceof WSErrorHandler) {
self::$_handler = $handler;
}
}
/**
* Returns the error handler
*
* @return WSErrorHandler Error handler
*/
public static function getErrorHandler() {
return self::$_handler;
}
/**
* Transforms the error into an array
*
* @return array Associative array with code and message
*/
public function toArray() {
return array('code' => $this->code, 'message' => $this->message);
}
}
/**
* Interface that must be implemented by any error handler
*/
interface WSCMErrorHandler {
/**
* Handle method
*
* @param WSError Error
*/
public function handle($error);
}
/**
* Main class of the webservice. Webservice classes extend this class
*/
class WSCM {
/**
* Chamilo configuration
*
* @var array
*/
protected $_configuration;
/**
* Constructor
*/
public function __construct() {
$this->_configuration = $GLOBALS['_configuration'];
}
/**
* Verifies the API key
*
* @param string Secret key
* @return mixed WSError in case of failure, null in case of success
*/
protected function verifyKey($secret_key) {
$security_key = $_SERVER['REMOTE_ADDR'].$this->_configuration['security_key'];
if(!api_is_valid_secret_key($secret_key, $security_key)) {
return new WSCMError(1, "API key is invalid");
} else {
return null;
}
}
/**
* Verifies if the user is valid
*
* @param <String> $username of the user in chamilo
* @param <String> $pass of the same user (in MD5 of SHA)
*
* return "valid" if username e password are correct! Else, return a message error
*/
public function verifyUserPass($username, $pass) {
$login = $username;
$password = $pass;
//lookup the user in the main database
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$sql = "SELECT user_id, username, password, auth_source, active, expiration_date
FROM $user_table
WHERE username = '".trim(addslashes($login))."'";
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$uData = Database::fetch_array($result);
if ($uData['auth_source'] == PLATFORM_AUTH_SOURCE) {
$password = trim(stripslashes($password));
// Check the user's password
if ($password == $uData['password'] AND (trim($login) == $uData['username'])) {
// Check if the account is active (not locked)
if ($uData['active']=='1') {
// Check if the expiration date has not been reached
if ($uData['expiration_date']>date('Y-m-d H:i:s') OR $uData['expiration_date']=='0000-00-00 00:00:00') {
return "valid";
}
else
return get_lang('AccountExpired');
}
else
return get_lang('AccountInactive');
}
else
return get_lang('InvalidId');
}
else
return get_lang('AccountURLInactive');
}
return get_lang('InvalidId');
}
/**
* Return the encrypted pass
* @param <String> $pass
* @return <String> $pass encrypted
*/
public function encryptPass($pass){
return api_get_encrypted_password($pass);
}
/**
* Gets the real user id based on the user id field name and value. Note that if the user id field name is "chamilo_user_id", it will use the user id
* in the system database
*
* @param string User id field name
* @param string User id value
* @return mixed System user id if the user was found, WSError otherwise
*/
protected function getUserId($user_id_field_name, $user_id_value) {
if($user_id_field_name == "chamilo_user_id") {
if(UserManager::is_user_id_valid(intval($user_id_value))) {
return intval($user_id_value);
} else {
return new WSCMError(100, "User not found");
}
} else {
$user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name);
if($user_id == 0) {
return new WSCMError(100, "User not found");
} else {
return $user_id;
}
}
}
/**
* Gets the real course id based on the course id field name and value. Note that if the course id field name is "chamilo_course_id", it will use the course id
* in the system database
*
* @param string Course id field name
* @param string Course id value
* @return mixed System course id if the course was found, WSError otherwise
*/
protected function getCourseId($course_id_field_name, $course_id_value) {
if($course_id_field_name == "chamilo_course_id") {
if(CourseManager::get_course_code_from_course_id(intval($course_id_value)) != null) {
return intval($course_id_value);
} else {
return new WSCMError(200, "Course not found");
}
} else {
$course_code = CourseManager::get_course_code_from_original_id($course_id_value, $course_id_field_name);
if($course_code == 0) {
return new WSCMError(200, "Course not found");
} else {
$course_info = CourseManager::get_course_information($course_code);
return $course_info['id'];
}
}
}
/**
* Gets the real session id based on the session id field name and value. Note that if the session id field name is "chamilo_session_id", it will use the session id
* in the system database
*
* @param string Session id field name
* @param string Session id value
* @return mixed System session id if the session was found, WSError otherwise
*/
protected function getSessionId($session_id_field_name, $session_id_value) {
if($session_id_field_name == "chamilo_session_id") {
$session = SessionManager::fetch((int)$session_id_value);
if(!empty($session)) {
return intval($session_id_value);
} else {
return new WSCMError(300, "Session not found");
}
} else {
$session_id = SessionManager::get_session_id_from_original_id($session_id_value, $session_id_field_name);
if($session_id == 0) {
return new WSCMError(300, "Session not found");
} else {
return $session_id;
}
}
}
/**
* Handles an error by calling the WSError error handler
*
* @param WSError Error
*/
protected function handleError($error) {
$handler = WSCMError::getErrorHandler();
$handler->handle($error);
}
/**
* Gets a successful result
*
* @return array Array with a code of 0 and a message 'Operation was successful'
*/
protected function getSuccessfulResult() {
return array('code' => 0, 'message' => 'Operation was successful');
}
/**
* Test function. Returns the string success
*
* @return string Success
*/
public function test() {
return "success";
}
/**
* *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not)
* @param <type> $string
* @return <type> $string
*/
public function nl2br_revert($string) {
return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string);
}
}

@ -0,0 +1,187 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once(dirname(__FILE__).'/../announcements/announcements.inc.php');
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'course.lib.php';
require_once $libpath.'groupmanager.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Description of cm_soap_inbox
*
* @author marcosousa
*/
class WSCMAnnouncements extends WSCM {
public function get_announcements_id($username, $password, $course_code)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$result = self::get_announcements($username, $course_code);
$announcements = "#";
while ($announcement = Database::fetch_array($result)) {
$announcements .= $announcement['id']."#";
}
return $announcements;
} else
return get_lang('InvalidId');
}
public function get_announcement_data($username, $password, $course_code, $announcement_id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$htmlcode = false;
$user_id = UserManager::get_user_id_from_username($username);
$result = self::get_announcements($username, $course_code, $announcement_id);
while($announcement = Database::fetch_array($result))
{
$announcements[] = $announcement;
}
switch ($field)
{
case 'sender':
$field_table = "insert_user_id";
$sender = UserManager::get_user_info_by_id($announcements[0][$field_table]);
$announcements[0][$field_table] = $sender['firstname']." ".$sender['lastname'];
break;
case 'title' :
$htmlcode = true;
$field_table = "title";
break;
case 'date' :
$field_table = "end_date";
break;
case 'content' :
$htmlcode = true;
$field_table = "content";
$announcements[0][$field_table] = nl2br_revert($announcements[0][$field_table]);
break;
default :
$field_table = "title";
}
return (htmlcode) ? html_entity_decode($announcements[0][$field_table]) : $announcements[0][$field_table];
}else
return get_lang('InvalidId');
}
private function get_announcements($username, $course_code, $announcement_id = 0)
{
$session_id = api_get_session_id();
$condition_session = api_get_session_condition($session_id);
$announcement_id = ($announcement_id == 0) ? "" : "AND announcement.id=".$announcement_id;
$user_id = UserManager::get_user_id_from_username($username);
//$listOfCourses = CourseManager::get_course_information_by_id($course_id);
$course_info = CourseManager::get_course_information($course_code);
$course_db = $course_info['db_name'];
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY, $course_db);
$tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT, $course_db);
$maximum = '12';
$group_memberships=GroupManager::get_group_ids($course_db, $user_id);
if (api_get_group_id() == 0) {
$cond_user_id = " AND ( ip.to_user_id='".$user_id."'" .
"OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
} else {
$cond_user_id = " AND ( ip.to_user_id='".$user_id."'" .
"OR ip.to_group_id IN (0, ".api_get_group_id().")) ";
}
// the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
if (is_array($group_memberships) && count($group_memberships)>0) {
$sql="SELECT
announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
$announcement_id
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0,$maximum";
} else {
// the user is not member of any group
// this is an identified user => show the general announcements AND his personal announcements
if ($user_id) {
if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
$cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0')) ";
} else {
$cond_user_id = " AND ( ip.to_user_id='".$user_id."' OR ip.to_group_id='0') ";
}
$sql="SELECT
announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
$announcement_id
$cond_user_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0,$maximum";
} else {
if (api_get_course_setting('allow_user_edit_announcement')) {
$cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0') ";
} else {
$cond_user_id = " AND ip.to_group_id='0' ";
}
// the user is not identiefied => show only the general announcements
$sql="SELECT
announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
FROM $tbl_announcement announcement, $tbl_item_property ip
WHERE announcement.id = ip.ref
AND ip.tool='announcement'
AND ip.visibility='1'
AND ip.to_group_id='0'
$announcement_id
$condition_session
GROUP BY ip.ref
ORDER BY display_order DESC
LIMIT 0,$maximum";
}
}
$result = Database::query($sql);
return $result;
}
}
/*
echo "aqui: ";
$aqui = new WSCMAnnouncements();
echo "<pre>";
//print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
print_r($aqui->get_announcement_data("aluno", "c4ca4238a0b923820dcc509a6f75849b", "P0204", "17", "title"));
echo "</pre>";
*/

@ -0,0 +1,527 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'course.lib.php';
require_once $libpath.'add_course.lib.inc.php';
require_once $libpath.'course_description.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Web services available for the Course module. This class extends the WS class
*/
class WSCMCourse extends WSCM {
/**
* Deletes a course (helper method)
*
* @param string Course id field name
* @param string Course id value
* @return mixed True if the course was successfully deleted, WSError otherwise
*/
protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSCMError) {
return $course_id;
} else {
$course_code = CourseManager::get_course_code_from_course_id($course_id);
CourseManager::delete_course($course_code);
return true;
}
}
/**
* Deletes a course
*
* @param string API secret key
* @param string Course id field name
* @param string Course id value
*/
public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
if($result instanceof WSError) {
$this->handleError($result);
}
}
}
/**
* Deletes multiple courses
*
* @param string API secret key
* @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
* @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
* than 0, an error occured
*/
public function DeleteCourses($secret_key, $courses) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$results = array();
foreach($users as $user) {
$result_tmp = array();
$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
$result_tmp['course_id_value'] = $course['course_id_value'];
if($result_op instanceof WSCMError) {
// Return the error in the results
$result_tmp['result'] = $result_op->toArray();
} else {
$result_tmp['result'] = $this->getSuccessfulResult();
}
$results[] = $result_tmp;
}
return $results;
}
}
/**
* Creates a course (helper method)
*
* @param string Title
* @param string Category code
* @param string Wanted code. If it's not defined, it will be generated automatically
* @param string Tutor name
* @param string Course admin user id field name
* @param string Course admin user id value
* @param string Course language
* @param string Course id field name
* @param string Course id value
* @param array Course extra fields
* @return mixed Generated id if creation was successful, WSError otherwise
*/
protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
// Add the original course id field name and value to the extra fields if needed
$extras_associative = array();
if($course_id_field_name != "chamilo_course_id") {
$extras_associative[$course_id_field_name] = $course_id_value;
}
foreach($extras as $extra) {
$extras_associative[$extra['field_name']] = $extra['field_value'];
}
$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
if($course_admin_id instanceof WSError) {
return $course_admin_id;
}
if($wanted_code == '') {
$wanted_code = generate_course_code($title);
}
$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
if (!$result) {
return new WSError(202, 'There was an error creating the course');
} else {
// Update extra fields
foreach($extras_associative as $fname => $fvalue) {
CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
}
// Get course id
$course_info = CourseManager::get_course_information($result);
return $course_info['id'];
}
}
/**
* Creates a course
*
* @param string API secret key
* @param string Title
* @param string Category code
* @param string Wanted code. If it's not defined, it will be generated automatically
* @param string Tutor name
* @param string Course admin user id field name
* @param string Course admin user id value
* @param string Course language
* @param string Course id field name
* @param string Course id value
* @param array Course extra fields
* @return int Course id generated
*/
public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
// First, verify the secret key
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
if($result instanceof WSError) {
$this->handleError($result);
} else {
return $result;
}
}
}
/**
* Create multiple courses
*
* @param string API secret key
* @param array Courses to be created, with elements following the structure presented in CreateCourse
* @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
*/
public function CreateCourses($secret_key, $courses) {
// First, verify the secret key
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSCMError) {
$this->handleError($verifKey);
} else {
$results = array();
foreach($courses as $course) {
$result_tmp = array();
extract($course);
$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
if($result instanceof WSCMError) {
$result_tmp['result'] = $result->toArray();
$result_tmp['course_id_value'] = $course_id_value;
$result_tmp['course_id_generated'] = 0;
} else {
$result_tmp['result'] = $this->getSuccessfulResult();
$result_tmp['course_id_value'] = $course_id_value;
$result_tmp['course_id_generated'] = $result;
}
$results[] = $result_tmp;
}
return $results;
}
}
/**
* Edits a course (helper method)
*
* @param string Course id field name
* @param string Course id value
* @param string Title
* @param string Category code
* @param string Department name
* @param string Department url
* @param string Course language
* @param int Visibility
* @param int Subscribe (0 = denied, 1 = allowed)
* @param int Unsubscribe (0 = denied, 1 = allowed)
* @param string Visual code
* @param array Course extra fields
* @return mixed True in case of success, WSError otherwise
*/
protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSCMError) {
return $course_id;
} else {
$attributes = array();
if(!is_empty($title)) {
$attributes['title'] = $title;
}
if(!is_empty($category_code)) {
$attributes['category_code'] = $category_code;
}
if(!is_empty($department_name)) {
$attributes['department_name'] = $department_name;
}
if(!is_empty($department_url)) {
$attributes['department_url'] = $department_url;
}
if(!is_empty($language)) {
$attributes['course_language'] = $language;
}
if($visibility != '') {
$attributes['visibility'] = (int)$visibility;
}
if($subscribe != '') {
$attributes['subscribe'] = (int)$subscribe;
}
if($unsubscribe != '') {
$attributes['unsubscribe'] = (int)$unsubscribe;
}
if(!is_empty($visual_code)) {
$attributes['visual_code'] = $visual_code;
}
if(!is_empty($attributes)) {
CourseManager::update_attributes($course_id, $attributes);
}
if(!empty($extras)) {
$course_code = CourseManager::get_course_code_from_course_id($course_id);
$extras_associative = array();
foreach($extras as $extra) {
$extras_associative[$extra['field_name']] = $extra['field_value'];
}
foreach($extras_associative as $fname => $fvalue) {
CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
}
}
return true;
}
}
/**
* Edits a course
*
* @param string API secret key
* @param string Course id field name
* @param string Course id value
* @param string Title
* @param string Category code
* @param string Department name
* @param string Department url
* @param string Course language
* @param int Visibility
* @param int Subscribe (0 = denied, 1 = allowed)
* @param int Unsubscribe (0 = denied, 1 = allowed)
* @param string Visual code
* @param array Course extra fields
*/
public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSCMError) {
$this->handleError($verifKey);
} else {
$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
if($result instanceof WSCMError) {
$this->handleError($result);
}
}
}
/**
* List courses
*
* @param string API secret key
* @param string Course id field name. Use "chamilo_course_id" to use internal id
* @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
* 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
*/
public function ListCourses($secret_key, $course_id_field_name) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$courses_result = array();
$category_names = array();
$courses = CourseManager::get_courses_list();
foreach($courses as $course) {
$course_tmp = array();
$course_tmp['id'] = $course['id'];
$course_tmp['code'] = $course['code'];
$course_tmp['title'] = $course['title'];
$course_tmp['language'] = $course['course_language'];
$course_tmp['visibility'] = $course['visibility'];
// Determining category name
if($category_names[$course['category_code']]) {
$course_tmp['category_name'] = $category_names[$course['category_code']];
} else {
$category = CourseManager::get_course_category($course['category_code']);
$category_names[$course['category_code']] = $category['name'];
$course_tmp['category_name'] = $category['name'];
}
// Determining number of students registered in course
$user_list = CourseManager::get_user_list_from_course_code($course['code'], false);
$course_tmp['number_students'] = count($user_list);
// Determining external course id
$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
$courses_result[] = $course_tmp;
}
return $courses_result;
}
}
/**
* Subscribe or unsubscribe user to a course (helper method)
*
* @param string Course id field name. Use "chamilo_course_id" to use internal id
* @param string Course id value.
* @param string User id field name. Use "chamilo_user_id" to use internal id
* @param string User id value
* @param int Set to 1 to subscribe, 0 to unsubscribe
* @param int Status (STUDENT or TEACHER) Used for subscription only
* @return mixed True if subscription or unsubscription was successful, false otherwise
*/
protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSError) {
return $course_id;
} else {
$user_id = $this->getUserId($user_id_field_name, $user_id_value);
if($user_id instanceof WSError) {
return $user_id;
} else {
$course_code = CourseManager::get_course_code_from_course_id($course_id);
if($state == 0) {
// Unsubscribe user
CourseManager::unsubscribe_user($user_id, $course_code);
return true;
} else {
// Subscribe user
if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
return true;
} else {
return new WSError(203, 'An error occured subscribing to this course');
}
}
}
}
}
/**
* Subscribe user to a course
*
* @param string API secret key
* @param string Course id field name. Use "chamilo_course_id" to use internal id
* @param string Course id value.
* @param string User id field name. Use "chamilo_user_id" to use internal id
* @param string User id value
* @param int Status (1 = Teacher, 5 = Student)
*/
public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
if($result instanceof WSError) {
$this->handleError($result);
}
}
}
/**
* Unsusbscribe user from course
*
* @param string API secret key
* @param string Course id field name. Use "chamilo_course_id" to use internal id
* @param string Course id value.
* @param string User id field name. Use "chamilo_user_id" to use internal id
* @param string User id value
*/
public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
if($result instanceof WSError) {
$this->handleError($result);
}
}
}
/**
* Returns the descriptions of a course, along with their id
*
* @param string API secret key
* @param string Course id field name
* @param string Course id value
* @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
*/
public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSError) {
return $course_id;
} else {
// Course exists, get its descriptions
$descriptions = CourseDescription::get_descriptions($course_id);
$results = array();
foreach($descriptions as $description) {
$results[] = array('course_desc_id' => $description->get_description_type(),
'course_desc_title' => $description->get_title(),
'course_desc_content' => $description->get_content());
}
return $results;
}
}
}
/**
* Edit course description
*
* @param string API secret key
* @param string Course id field name
* @param string Course id value
* @param int Category id from course description
* @param string Description title
* @param string Course description content
*/
public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
$verifKey = $this->verifyKey($secret_key);
if($verifKey instanceof WSError) {
$this->handleError($verifKey);
} else {
$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
if($course_id instanceof WSError) {
return $course_id;
} else {
// Create the new course description
$cd = new CourseDescription();
$cd->set_description_type($course_desc_id);
$cd->set_title($course_desc_title);
$cd->set_content($course_desc_content);
$cd->set_session_id(0);
// Get course info
$course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
// Check if this course description exists
$descriptions = CourseDescription::get_descriptions($course_id);
$exists = false;
foreach($descriptions as $description) {
if($description->get_description_type() == $course_desc_id) {
$exists = true;
}
}
if (!$exists) {
$cd->set_progress(0);
$cd->insert($course_info['db_name']);
} else {
$cd->update($course_info['db_name']);
}
}
}
}
public function unreadMessage($username, $password)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$table_message = Database::get_main_table(TABLE_MESSAGE);
$user_id = UserManager::get_user_id_from_username($username);
$condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
$sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
$sql_result = Database::query($sql_query);
$result = Database::fetch_array($sql_result);
return $result['number_messages'];
}
return "0";
}
public function get_message_data($username, $password)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = get_user_id_from_username($username);
}
}
public function nada($username, $password)
{
if($this->verifyUserPass($username, $password) == "valid")
return $username.$password;
return $username;
}
}

@ -0,0 +1,56 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'course.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Description of cm_soap_inbox
*
* @author marcosousa
*/
class WSCMCourses extends WSCM {
public function get_courses_code($username, $password)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
$listOfCourses = UserManager::get_personal_session_course_list($user_id);
$courses_id = "#";
foreach ($listOfCourses as $course){
$courses_id .= $course['c']."#";
}
return $courses_id;
} else
return get_lang('InvalidId');
}
public function get_course_title($username, $password, $course_code)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_info = CourseManager::get_course_information($course_code);
return $course_info['title'];
} else
return get_lang('InvalidId');
}
}
/*
echo "aqui: ";
$aqui = new WSCMCourses();
echo "<pre>";
//print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
print_r($aqui->get_course_title("aluno", "c4ca4238a0b923820dcc509a6f75849b", "P0204"));
echo "</pre>";
*/

@ -0,0 +1,293 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
require_once(dirname(__FILE__).'/../forum/forumconfig.inc.php');
require_once(dirname(__FILE__).'/../forum/forumfunction.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'course.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Description of cm_soap_inbox
*
* @author marcosousa
*/
class WSCMForum extends WSCM {
public function get_foruns_id($username, $password, $course_code)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$foruns_info = get_forums($id='', $course_db['db_name']);
$foruns_id = '#';
foreach ($foruns_info as $forum)
{
if( isset($forum['forum_id']))
{
$foruns_id .= $forum['forum_id']."#";
}
}
return $foruns_id;
} else
return get_lang('InvalidId');
}
public function get_forum_title($username, $password, $course_code, $forum_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$table_forums = Database :: get_course_table(TABLE_FORUM, $course_db['db_name']);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']);
$sql="SELECT * FROM ".$table_forums." forums, ".$table_item_property." item_properties
WHERE item_properties.tool='".TOOL_FORUM."'
AND item_properties.ref='".Database::escape_string($forum_id)."'
AND forums.forum_id='".Database::escape_string($forum_id)."'";
$result=Database::query($sql);
$forum_info=Database::fetch_array($result);
$forum_info['approval_direct_post'] = 0; // we can't anymore change this option, so it should always be activated
$forum_title = utf8_decode($forum_info['forum_title']);
return $forum_title;
} else
return get_lang('InvalidId');
}
public function get_forum_threads_id($username, $password, $course_code, $forum_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$threads_info = get_threads($forum_id, $course_db['db_name']);
$threads_id = '#';
foreach ($threads_info as $thread)
{
if( isset($thread['thread_id']))
{
$threads_id .= $thread['thread_id']."#";
}
}
return $threads_id;
} else
return get_lang('InvalidId');
}
public function get_forum_thread_data($username, $password, $course_code, $thread_id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']);
$sql="SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties
WHERE item_properties.tool='".TOOL_FORUM_THREAD."'
AND item_properties.ref='".Database::escape_string($thread_id)."'
AND threads.thread_id='".Database::escape_string($thread_id)."'";
$result=Database::query($sql);
$thread_info=Database::fetch_array($result);
switch ($field)
{
case 'title':
$htmlcode = true;
$field_table = "thread_title";
break;
case 'date' :
$field_table = "thread_date";
break;
case 'sender' :
$field_table = "insert_user_id";
break;
case 'sender_name' :
$user_id = $thread_info[insert_user_id];
$user_info = UserManager::get_user_info_by_id($user_id);
return $user_info['firstname'];
break;
default :
$field_table = "title";
}
return $thread_info[$field_table];
} else
return get_lang('InvalidId');
}
public function get_forum_thread_title($username, $password, $course_code, $thread_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_db['db_name']);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']);
$sql="SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties
WHERE item_properties.tool='".TOOL_FORUM_THREAD."'
AND item_properties.ref='".Database::escape_string($thread_id)."'
AND threads.thread_id='".Database::escape_string($thread_id)."'";
$result=Database::query($sql);
$thread_info=Database::fetch_array($result);
$htmlcode = true;
$field_table = "thread_title";
return $thread_info[$field_table];
} else
return get_lang('InvalidId');
}
public function get_posts_id($username, $password, $course_code, $thread_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST, $course_db['db_name']);
// note: change these SQL so that only the relevant fields of the user table are used
if (api_is_allowed_to_edit(null,true)) {
$sql = "SELECT * FROM $table_posts posts
LEFT JOIN $table_users users
ON posts.poster_id=users.user_id
WHERE posts.thread_id='".Database::escape_string($thread_id)."'
ORDER BY posts.post_id ASC";
} else {
// students can only se the posts that are approved (posts.visible='1')
$sql = "SELECT * FROM $table_posts posts
LEFT JOIN $table_users users
ON posts.poster_id=users.user_id
WHERE posts.thread_id='".Database::escape_string($thread_id)."'
AND posts.visible='1'
ORDER BY posts.post_id ASC";
}
$result=Database::query($sql);
while ($row=Database::fetch_array($result)) {
$posts_info[]=$row;
}
$posts_id = '#';
foreach ($posts_info as $post)
{
if( isset($post['post_id']))
{
$posts_id .= $post['post_id']."#";
}
}
return $posts_id;
} else
return get_lang('InvalidId');
}
public function get_post_data($username, $password, $course_code, $post_id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST, $course_db['db_name']);
$table_users = Database :: get_main_table(TABLE_MAIN_USER);
$sql="SELECT * FROM ".$table_posts."posts, ".$table_users." users WHERE posts.poster_id=users.user_id AND posts.post_id='".Database::escape_string($post_id)."'";
$result=Database::query($sql);
$post_info =Database::fetch_array($result);
$htmlcode = false;
switch ($field)
{
case 'title':
$htmlcode = true;
$field_table = "post_title";
break;
case 'text' :
$htmlcode = true;
$field_table = "post_text";
break;
case 'date' :
$field_table = "post_date";
break;
case 'sender' :
$field_table = "user_id";
break;
case 'sender_name' :
$field_table = "firstname";
break;
default :
$htmlcode = true;
$field_table = "title";
}
return (htmlcode) ? html_entity_decode($post_info[$field_table]) : $post_info[$field_table];
} else
return get_lang('InvalidId');
}
public function send_post($username, $password, $course_code, $forum_id, $thread_id, $title, $content)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$course_db = CourseManager::get_course_information($course_code);
$user_id = UserManager::get_user_id_from_username($username);
$table_threads = Database :: get_course_table(TABLE_FORUM_THREAD, $course_db['db_name']);
$forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT, $course_db['db_name']);
$table_posts = Database :: get_course_table(TABLE_FORUM_POST, $course_db['db_name']);
$post_date=date('Y-m-d H:i:s');
$visible=1;
$has_attachment=false;
$my_post = '';
$post_notification = '';
$content = nl2br($content);
$title = htmlentities($title);
$content = htmlentities($content);
$sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible)
VALUES ('".Database::escape_string($title)."',
'".Database::escape_string(isset($content) ? (api_html_entity_decode($content)) : null)."',
'".Database::escape_string($thread_id)."',
'".Database::escape_string($forum_id)."',
'".Database::escape_string($user_id)."',
'".Database::escape_string($post_date)."',
'".Database::escape_string(isset($post_notification)?$post_notification:null)."',
'".Database::escape_string(isset($my_post)?$my_post:null)."',
'".Database::escape_string($visible)."')";
$result=Database::query($sql);
return "Post enviado!";
//return $sql;
//send_notification_mails($thread_id, $values);
} else
return get_lang('InvalidId');
}
}
/*
echo "aqui: ";
$aqui = new WSCMForum();
echo "<pre>";
//print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
//print_r($aqui->get_post_data("aluno", "c4ca4238a0b923820dcc509a6f75849b", "95", "sender_name"));
print_r($aqui->send_post("aluno", "c4ca4238a0b923820dcc509a6f75849b", "P0304", "3", "15", "títle", "conteúdo222222"));
echo "</pre>";
*/

@ -0,0 +1,228 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'message.lib.php';
require_once $libpath.'usermanager.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Description of cm_soap_inbox
*
* @author marcosousa
*/
class WSCMInbox extends WSCM {
public function unreadMessage($username, $password)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$table_message = Database::get_main_table(TABLE_MESSAGE);
$user_id = UserManager::get_user_id_from_username($username);
$condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
$sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
$sql_result = Database::query($sql_query);
$result = Database::fetch_array($sql_result);
return $result['number_messages'];
}
return "0";
}
public function get_message_id($username, $password, $from, $number_of_items)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql_query = "SELECT id FROM $table_message " .
" WHERE user_receiver_id=".$user_id." AND msg_status IN (0,1)" .
" ORDER BY send_date LIMIT $from,$number_of_items";
$sql_result = Database::query($sql_query);
$message = "#";
while ($result = Database::fetch_row($sql_result)) {
$message .= $result[0]."#";
}
return $message;
} else
return get_lang('InvalidId');
}
public function get_message_data($username, $password, $message_id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$htmlcode = false;
$user_id = UserManager::get_user_id_from_username($username);
switch ($field)
{
case 'sender':
$field_table = "user_sender_id";
break;
case 'title' :
$htmlcode = true;
$field_table = "title";
break;
case 'date' :
$field_table = "send_date";
break;
case 'status' :
$field_table = "msg_status";
break;
case 'content' :
$this->set_message_as_read($user_id, $message_id);
$htmlcode = true;
$field_table = "content";
break;
default :
$field_table = "title";
}
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql_query = "SELECT ".$field_table." FROM $table_message " .
" WHERE user_receiver_id=".$user_id." AND id=".$message_id;
$sql_result = Database::query($sql_query);
$result = Database::fetch_row($sql_result);
return (htmlcode) ? html_entity_decode($result[0]) : $result[0];
}else
return get_lang('InvalidId');
}
public function get_message_id_sent($username, $password, $from, $number_of_items)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql_query = "SELECT id FROM $table_message " .
"WHERE user_sender_id=".$user_id." AND msg_status=".MESSAGE_STATUS_OUTBOX." " .
"ORDER BY send_date LIMIT $from,$number_of_items";
$sql_result = Database::query($sql_query);
$message = "#";
while ($result = Database::fetch_row($sql_result)) {
$message .= $result[0]."#";
}
return $message;
} else
return get_lang('InvalidId');
}
public function get_message_data_sent($username, $password, $id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$htmlcode = false;
switch ($field)
{
case 'sender':
$field_table = "user_sender_id";
break;
case 'title' :
$htmlcode = true;
$field_table = "title";
break;
case 'date' :
$field_table = "send_date";
break;
case 'status' :
$field_table = "msg_status";
break;
case 'content' :
$htmlcode = true;
$field_table = "content";
break;
default :
$field_table = "title";
}
$user_id = UserManager::get_user_id_from_username($username);
$table_message = Database::get_main_table(TABLE_MESSAGE);
$sql_query = "SELECT ".$field_table." FROM $table_message " .
" WHERE user_sender_id=".$user_id." AND id=".$id;
$sql_result = Database::query($sql_query);
$result = Database::fetch_row($sql_result);
return (htmlcode) ? html_entity_decode($result[0]) : $result[0];
}else
return get_lang('InvalidId');
}
public function message_send($username, $password, $receiver_user_id, $subject, $content)
{
//TODO: verificar data de envio. Esta divergindo de data!
if($this->verifyUserPass($username, $password) == "valid")
{
$group_id = intval(0);
$parent_id = intval(0);
$edit_message_id = intval(0);
$sent_email = false;
$user_sender_id = UserManager::get_user_id_from_username($username);
$subject = htmlentities($subject);
$content = htmlentities($content);
$table_message = Database::get_main_table(TABLE_MESSAGE);
$query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '1', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')";
$result = Database::query($query);
$query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '4', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')";
$result = Database::query($query);
$inbox_last_id = Database::insert_id();
return $inbox_last_id;
} else
return get_lang('InvalidId');
}
protected function set_message_as_read($user_id, $message_id){
$table_message = Database::get_main_table(TABLE_MESSAGE);
$query = "UPDATE $table_message SET msg_status = '".MESSAGE_STATUS_NEW."' WHERE user_receiver_id=".$user_id." AND id='".$message_id."';";
$result = Database::query($query);
}
}
/*
echo "aqui: ";
$aqui = new WSCMInbox();
//print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
print_r($aqui->message_send("aluno", "356a192b7913b04c54574d18c28d46e6395428ab", "1", "Título da mensagem", "Conteúdo da mensagem com ç ã"));
*/

@ -0,0 +1,179 @@
<?php
require_once(dirname(__FILE__).'/../inc/global.inc.php');
$libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'social.lib.php';
require_once(dirname(__FILE__).'/cm_webservice.php');
/**
* Description of cm_soap_user
*
* @author marcosousa
*/
class WSCMUser extends WSCM {
public function find_id_user($username, $password, $name)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$listResult = "#";
$listArrayResult = Array();
$listArray = Array();
$list = $this->get_user_list_like_start(array('firstname'=>$name), array('firstname'));
foreach ($list as $userData)
{
$listArray[] = $userData['user_id'];
}
$list = $this->get_user_list_like_start(array('lastname'=>$name), array('firstname'));
foreach ($list as $userData)
{
$listArray[] = $userData['user_id'];
}
$list = $this->get_user_list_like_start(array('email'=>$name), array('firstname'));
foreach ($list as $userData)
{
$listArray[] = $userData['user_id'];
}
$listArrayResult = array_unique($listArray);
foreach($listArrayResult as $result)
{
$listResult .= $result . "#";
}
return $listResult;
}
return "0";
}
public function get_link_user_picture($username, $password, $id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$userPic = UserManager::get_user_picture_path_by_id($id, "web");
if(empty ($userPic['file']))
return "0";
return $userPic['dir'].$userPic['file'];
}
return "0";
}
public function get_user_name($username, $password, $id, $field)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$userInfo = UserManager::get_user_info_by_id($id);
switch ($field)
{
case 'firstname':
return $userInfo['firstname'];
break;
case 'lastname' :
return $userInfo['lastname'];
break;
case 'bothfl' :
return $userInfo['firstname']." ".$userInfo['lastname'];
break;
case 'bothlf' :
return $userInfo['lastname']." ".$userInfo['firstname'];
break;
default :
return $userInfo['firstname'];
}
return "0";
}
return "0";
}
public function send_invitation($username, $password, $userfriend_id, $content_message = '')
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
$message_title = get_lang('Invitation');
$count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message);
if ($count_is_true) {
return Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES,$charset),false);
}else {
return Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES,$charset),false);
}
}
return get_lang('InvalidId');
}
public function accept_friend($username, $password, $userfriend_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
UserManager::relate_users($userfriend_id, $user_id, USER_RELATION_TYPE_FRIEND);
SocialManager::invitation_accepted($userfriend_id, $user_id);
return get_lang('AddedContactToList');
}
return get_lang('InvalidId');
}
public function denied_invitation($username, $password, $userfriend_id)
{
if($this->verifyUserPass($username, $password) == "valid")
{
$user_id = UserManager::get_user_id_from_username($username);
SocialManager::invitation_denied($userfriend_id, $user_id);
return get_lang('InvitationDenied');
}
return get_lang('InvalidId');
}
/**
* Get a list of users of which the given conditions match with a LIKE '%cond%'
* @param array $conditions a list of condition (exemple : status=>STUDENT)
* @param array $order_by a list of fields on which sort
* @return array An array with all users of the platform.
* @todo optional course code parameter, optional sorting parameters...
*/
private static function get_user_list_like_start($conditions = array(), $order_by = array()) {
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$return_array = array();
$sql_query = "SELECT * FROM $user_table";
if (count($conditions) > 0) {
$sql_query .= ' WHERE ';
foreach ($conditions as $field => $value) {
$field = Database::escape_string($field);
$value = Database::escape_string($value);
$sql_query .= $field.' LIKE \''.$value.'%\'';
}
}
if (count($order_by) > 0) {
$sql_query .= ' ORDER BY '.Database::escape_string(implode(',', $order_by));
}
$sql_result = Database::query($sql_query);
while ($result = Database::fetch_array($sql_result)) {
$return_array[] = $result;
}
return $return_array;
}
}
/*
echo "aqui: ";
$aqui = new WSCMUser();
//print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
//print_r($aqui->send_invitation("marco", "c4ca4238a0b923820dcc509a6f75849b", "1", "oia ai"));
print_r($aqui->denied_invitation("admin", "c4ca4238a0b923820dcc509a6f75849b", "3"));
*/
?>
Loading…
Cancel
Save