cm_webservice_user.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. {
  45. $userPic = UserManager::get_user_picture_path_by_id($id, "web");
  46. if(empty ($userPic['file']))
  47. return "0";
  48. return $userPic['dir'].$userPic['file'];
  49. }
  50. return "0";
  51. }
  52. public function get_user_name($username, $password, $id, $field)
  53. {
  54. if($this->verifyUserPass($username, $password) == "valid")
  55. {
  56. $userInfo = UserManager::get_user_info_by_id($id);
  57. switch ($field)
  58. {
  59. case 'firstname':
  60. return $userInfo['firstname'];
  61. break;
  62. case 'lastname' :
  63. return $userInfo['lastname'];
  64. break;
  65. case 'bothfl' :
  66. return $userInfo['firstname']." ".$userInfo['lastname'];
  67. break;
  68. case 'bothlf' :
  69. return $userInfo['lastname']." ".$userInfo['firstname'];
  70. break;
  71. default :
  72. return $userInfo['firstname'];
  73. }
  74. return "0";
  75. }
  76. return "0";
  77. }
  78. public function send_invitation($username, $password, $userfriend_id, $content_message = '')
  79. {
  80. global $charset;
  81. if($this->verifyUserPass($username, $password) == "valid")
  82. {
  83. $user_id = UserManager::get_user_id_from_username($username);
  84. $message_title = get_lang('Invitation');
  85. $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message);
  86. if ($count_is_true) {
  87. return Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES,$charset),false);
  88. }else {
  89. return Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES,$charset),false);
  90. }
  91. }
  92. return get_lang('InvalidId');
  93. }
  94. public function accept_friend($username, $password, $userfriend_id)
  95. {
  96. if($this->verifyUserPass($username, $password) == "valid")
  97. {
  98. $user_id = UserManager::get_user_id_from_username($username);
  99. UserManager::relate_users($userfriend_id, $user_id, USER_RELATION_TYPE_FRIEND);
  100. SocialManager::invitation_accepted($userfriend_id, $user_id);
  101. return get_lang('AddedContactToList');
  102. }
  103. return get_lang('InvalidId');
  104. }
  105. public function denied_invitation($username, $password, $userfriend_id)
  106. {
  107. if($this->verifyUserPass($username, $password) == "valid")
  108. {
  109. $user_id = UserManager::get_user_id_from_username($username);
  110. SocialManager::invitation_denied($userfriend_id, $user_id);
  111. return get_lang('InvitationDenied');
  112. }
  113. return get_lang('InvalidId');
  114. }
  115. /**
  116. * Get a list of users of which the given conditions match with a LIKE '%cond%'
  117. * @param array $conditions a list of condition (exemple : status=>STUDENT)
  118. * @param array $order_by a list of fields on which sort
  119. * @return array An array with all users of the platform.
  120. * @todo optional course code parameter, optional sorting parameters...
  121. *@todo Use the UserManager class
  122. */
  123. private static function get_user_list_like_start($conditions = array(), $order_by = array()) {
  124. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  125. $return_array = array();
  126. $sql_query = "SELECT * FROM $user_table";
  127. if (count($conditions) > 0) {
  128. $sql_query .= ' WHERE ';
  129. foreach ($conditions as $field => $value) {
  130. $field = Database::escape_string($field);
  131. $value = Database::escape_string($value);
  132. $sql_query .= $field.' LIKE \''.$value.'%\'';
  133. }
  134. }
  135. if (count($order_by) > 0) {
  136. $sql_query .= ' ORDER BY '.Database::escape_string(implode(',', $order_by));
  137. }
  138. $sql_result = Database::query($sql_query);
  139. while ($result = Database::fetch_array($sql_result)) {
  140. $return_array[] = $result;
  141. }
  142. return $return_array;
  143. }
  144. }
  145. /*
  146. echo "aqui: ";
  147. $aqui = new WSCMUser();
  148. //print_r($aqui->unreadMessage("aluno", "e695f51fe3dd6b7cf2be3188a614f10f"));
  149. //print_r($aqui->send_invitation("marco", "c4ca4238a0b923820dcc509a6f75849b", "1", "oia ai"));
  150. print_r($aqui->denied_invitation("admin", "c4ca4238a0b923820dcc509a6f75849b", "3"));
  151. */
  152. ?>