cm_webservice_user.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. require_once(dirname(__FILE__).'/../inc/global.inc.php');
  3. require_once(dirname(__FILE__).'/cm_webservice.php');
  4. /**
  5. * Description of cm_soap_user
  6. *
  7. * @author marcosousa
  8. */
  9. class WSCMUser extends WSCM {
  10. public function find_id_user($username, $password, $name)
  11. {
  12. if($this->verifyUserPass($username, $password) == "valid")
  13. {
  14. $listResult = "#";
  15. $listArrayResult = Array();
  16. $listArray = Array();
  17. $list = $this->get_user_list_like_start(array('firstname'=>$name), array('firstname'));
  18. foreach ($list as $userData)
  19. {
  20. $listArray[] = $userData['user_id'];
  21. }
  22. $list = $this->get_user_list_like_start(array('lastname'=>$name), array('firstname'));
  23. foreach ($list as $userData)
  24. {
  25. $listArray[] = $userData['user_id'];
  26. }
  27. $list = $this->get_user_list_like_start(array('email'=>$name), array('firstname'));
  28. foreach ($list as $userData)
  29. {
  30. $listArray[] = $userData['user_id'];
  31. }
  32. $listArrayResult = array_unique($listArray);
  33. foreach($listArrayResult as $result)
  34. {
  35. $listResult .= $result . "#";
  36. }
  37. return $listResult;
  38. }
  39. return "0";
  40. }
  41. public function get_link_user_picture($username, $password, $id)
  42. {
  43. if ($this->verifyUserPass($username, $password) == "valid") {
  44. $userPic = UserManager::getUserPicture($id);
  45. if (empty ($userPic)) {
  46. return "0";
  47. }
  48. return $userPic;
  49. }
  50. return "0";
  51. }
  52. public function get_user_name($username, $password, $id, $field)
  53. {
  54. if ($this->verifyUserPass($username, $password) == "valid") {
  55. $userInfo = api_get_user_info($id);
  56. switch ($field) {
  57. case 'firstname':
  58. return $userInfo['firstname'];
  59. break;
  60. case 'lastname' :
  61. return $userInfo['lastname'];
  62. break;
  63. case 'bothfl' :
  64. return $userInfo['firstname']." ".$userInfo['lastname'];
  65. break;
  66. case 'bothlf' :
  67. return $userInfo['lastname']." ".$userInfo['firstname'];
  68. break;
  69. default :
  70. return $userInfo['firstname'];
  71. }
  72. return "0";
  73. }
  74. return "0";
  75. }
  76. public function send_invitation($username, $password, $userfriend_id, $content_message = '')
  77. {
  78. global $charset;
  79. if ($this->verifyUserPass($username, $password) == "valid") {
  80. $user_id = UserManager::get_user_id_from_username($username);
  81. $message_title = get_lang('Invitation');
  82. $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message);
  83. if ($count_is_true) {
  84. return Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES,$charset),false);
  85. } else {
  86. return Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES,$charset),false);
  87. }
  88. }
  89. return get_lang('InvalidId');
  90. }
  91. public function accept_friend($username, $password, $userfriend_id)
  92. {
  93. if ($this->verifyUserPass($username, $password) == "valid") {
  94. $user_id = UserManager::get_user_id_from_username($username);
  95. UserManager::relate_users($userfriend_id, $user_id, USER_RELATION_TYPE_FRIEND);
  96. SocialManager::invitation_accepted($userfriend_id, $user_id);
  97. return get_lang('AddedContactToList');
  98. }
  99. return get_lang('InvalidId');
  100. }
  101. public function denied_invitation($username, $password, $userfriend_id)
  102. {
  103. if ($this->verifyUserPass($username, $password) == "valid") {
  104. $user_id = UserManager::get_user_id_from_username($username);
  105. SocialManager::invitation_denied($userfriend_id, $user_id);
  106. return get_lang('InvitationDenied');
  107. }
  108. return get_lang('InvalidId');
  109. }
  110. /**
  111. * Get a list of users of which the given conditions match with a LIKE '%cond%'
  112. * @param array $conditions a list of condition (exemple : status=>STUDENT)
  113. * @param array $order_by a list of fields on which sort
  114. * @return array An array with all users of the platform.
  115. * @todo optional course code parameter, optional sorting parameters...
  116. *@todo Use the UserManager class
  117. * @todo security filter order by
  118. */
  119. private static function get_user_list_like_start($conditions = array(), $order_by = array())
  120. {
  121. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  122. $return_array = array();
  123. $sql_query = "SELECT * FROM $user_table";
  124. if (count($conditions) > 0) {
  125. $sql_query .= ' WHERE ';
  126. foreach ($conditions as $field => $value) {
  127. $field = Database::escape_string($field);
  128. $value = Database::escape_string($value);
  129. $sql_query .= $field.' LIKE \''.$value.'%\'';
  130. }
  131. }
  132. $order = '';
  133. foreach ($order_by as $orderByItem) {
  134. $order .= Database::escape_string($orderByItem, null, false).', ';
  135. }
  136. $order = substr($order, 0, -2);
  137. if (count($order_by) > 0) {
  138. $sql_query .= ' ORDER BY '.$order;
  139. }
  140. $sql_result = Database::query($sql_query);
  141. while ($result = Database::fetch_array($sql_result)) {
  142. $return_array[] = $result;
  143. }
  144. return $return_array;
  145. }
  146. }
  147. /*
  148. echo "aqui: ";
  149. $aqui = new WSCMUser();
  150. //print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
  151. //print_r($aqui->send_invitation("marco", "c4ca4238a0b923820dcc509a6f75849b", "1", "oia ai"));
  152. print_r($aqui->denied_invitation("admin", "c4ca4238a0b923820dcc509a6f75849b", "3"));
  153. */