cm_webservice_user.php 5.7 KB

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