PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/IWusers/Controller/Ajax.php

https://github.com/intraweb-modules13/IWusers
PHP | 242 lines | 208 code | 27 blank | 7 comment | 46 complexity | 62bbfda29945d893f2b90d7987db168d MD5 | raw file
  1. <?php
  2. class IWusers_Controller_Ajax extends Zikula_Controller_AbstractAjax {
  3. public function orderGroupInfo($args) {
  4. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ)) {
  5. throw new Zikula_Exception_Fatal($this->__('No teniu autorització per accedir a aquesta informació.'));
  6. }
  7. $orderBy = $this->request->request->get('orderBy', '');
  8. if ($orderBy=='') $orderBy = "gid";
  9. $gi = UserUtil::getGroups('',$orderBy);
  10. foreach ($gi as $key => $value) {
  11. $groupInfo[] = array_slice($value,0,2);
  12. }
  13. $view = Zikula_View::getInstance($this->name);
  14. $view->assign('groupInfo', $groupInfo);
  15. $content = $view->fetch('IWusers_groupsTable.tpl');
  16. return new Zikula_Response_Ajax(array('content' => $content));
  17. }
  18. public function addContact($args) {
  19. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_READ)) {
  20. throw new Zikula_Exception_Forbidden();
  21. }
  22. $gid = FormUtil::getPassedValue('gid', -2, 'GET');
  23. if ($gid == -2) {
  24. AjaxUtil::error('no group id');
  25. }
  26. $fuid = FormUtil::getPassedValue('fuid', -1, 'GET');
  27. if ($fuid == -1) {
  28. AjaxUtil::error('no user id');
  29. }
  30. $action = FormUtil::getPassedValue('action', -1, 'GET');
  31. if ($action == -1) {
  32. AjaxUtil::error('no action defined');
  33. }
  34. $view = Zikula_View::getInstance('IWusers', false);
  35. if ($action == 'add') {
  36. if (!ModUtil::apiFunc('IWusers', 'user', 'addContant', array('fuid' => $fuid))) {
  37. AjaxUtil::error('error');
  38. }
  39. $view->assign('add', true);
  40. }
  41. if ($action == 'delete') {
  42. if (!ModUtil::apiFunc('IWusers', 'user', 'deleteContant', array('fuid' => $fuid))) {
  43. AjaxUtil::error('error');
  44. }
  45. $view->assign('add', false);
  46. }
  47. $view->assign('fuid', $fuid);
  48. $view->assign('gid', $gid);
  49. $vars = UserUtil::getVars($fuid);
  50. $view->assign('uname', $vars['uname']);
  51. $content = $view->fetch('IWusers_user_members_optionsContent.htm');
  52. AjaxUtil::output(array('fuid' => $fuid,
  53. 'content' => $content,
  54. 'gid' => $gid));
  55. }
  56. public function delUserGroup($args) {
  57. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN)) {
  58. throw new Zikula_Exception_Forbidden();
  59. }
  60. $uid = FormUtil::getPassedValue('uid', -1, 'GET');
  61. if ($uid == -1) {
  62. AjaxUtil::error('no user id');
  63. }
  64. $gid = FormUtil::getPassedValue('gid', -1, 'GET');
  65. if ($gid == -1) {
  66. AjaxUtil::error('no group id');
  67. }
  68. if (!ModUtil::apiFunc('groups', 'admin', 'removeuser', array('uid' => $uid,
  69. 'gid' => $gid))) {
  70. AjaxUtil::error('error deleting group');
  71. }
  72. AjaxUtil::output(array('uid' => $uid,
  73. 'gid' => $gid));
  74. }
  75. public function addUserGroup($args) {
  76. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN)) {
  77. throw new Zikula_Exception_Forbidden();
  78. }
  79. $uid = FormUtil::getPassedValue('uid', -1, 'GET');
  80. if ($uid == -1) {
  81. AjaxUtil::error('no user id');
  82. }
  83. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  84. $allGroups = ModUtil::func('IWmain', 'user', 'getAllGroups', array('sv' => $sv));
  85. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  86. $userGroups = ModUtil::func('IWmain', 'user', 'getAllUserGroups', array('sv' => $sv,
  87. 'uid' => $uid));
  88. $usersGroupsArray = array();
  89. foreach ($allGroups as $group) {
  90. if (!array_key_exists($group['id'], $userGroups)) {
  91. $userGroupsArray[] = array('id' => $group['id'],
  92. 'name' => $group['name']);
  93. }
  94. }
  95. // Create output object
  96. $view = Zikula_View::getInstance('IWusers', false);
  97. $view->assign('groups', $userGroupsArray);
  98. $view->assign('uid', $uid);
  99. $view->assign('list', true);
  100. $content = $view->fetch('IWusers_admin_addGroupForm.htm');
  101. AjaxUtil::output(array('uid' => $uid,
  102. 'content' => $content));
  103. }
  104. public function addGroupProceed($args) {
  105. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN)) {
  106. throw new Zikula_Exception_Forbidden();
  107. }
  108. $uid = FormUtil::getPassedValue('uid', -1, 'GET');
  109. if ($uid == -1) {
  110. AjaxUtil::error('no user id');
  111. }
  112. $gid = FormUtil::getPassedValue('gid', -1, 'GET');
  113. if ($gid == -1) {
  114. AjaxUtil::error('no group id');
  115. }
  116. if (!ModUtil::apiFunc('groups', 'admin', 'adduser', array('uid' => $uid,
  117. 'gid' => $gid))) {
  118. AjaxUtil::error('error adding group');
  119. }
  120. // Get all the groups information
  121. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  122. $groupsInfo = ModUtil::func('IWmain', 'user', 'getAllGroupsInfo', array('sv' => $sv));
  123. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  124. $groups = ModUtil::func('IWmain', 'user', 'getAllUserGroups', array('sv' => $sv,
  125. 'uid' => $uid));
  126. $userGroups = array();
  127. foreach ($groups as $group) {
  128. if ($group['id']) {
  129. array_push($userGroups, array('id' => $group['id'],
  130. 'name' => $groupsInfo[$group['id']]));
  131. }
  132. }
  133. $view = Zikula_View::getInstance('IWusers', false);
  134. $view->assign('user', array('groups' => $userGroups,
  135. 'uid' => $uid));
  136. $content = $view->fetch('IWusers_admin_userGroupsList.htm');
  137. $content1 = $view->fetch('IWusers_admin_addGroupForm.htm');
  138. AjaxUtil::output(array('uid' => $uid,
  139. 'content' => $content,
  140. 'content1' => $content1));
  141. }
  142. public function change($args) {
  143. if (!SecurityUtil::checkPermission('IWusers::', '::', ACCESS_ADMIN)) {
  144. AjaxUtil::error(DataUtil::formatForDisplayHTML($this->__('Sorry! No authorization to access this module.')));
  145. }
  146. $uid = FormUtil::getPassedValue('uid', -1, 'GET');
  147. if ($uid == -1)
  148. AjaxUtil::error('no change user id');
  149. // get user information
  150. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  151. $userAvatar = ModUtil::func('IWmain', 'user', 'getUserInfo', array('uid' => $uid,
  152. 'info' => 'na',
  153. 'sv' => $sv));
  154. $toDo = FormUtil::getPassedValue('toDo', -1, 'GET');
  155. if ($toDo == -1)
  156. AjaxUtil::error('no action defined');
  157. $chid = '_' . $userAvatar;
  158. $error = '';
  159. $path = ModUtil::getVar('IWmain', 'documentRoot') . '/' . ModUtil::getVar('IWusers', 'usersPictureFolder') . '/';
  160. if ($toDo == 'del') {
  161. //delete the file
  162. if (!ModUtil::func('IWusers', 'user', 'deleteAvatar', array('avatarName' => substr($chid, 0, -4),
  163. 'extensions' => array('jpg',
  164. 'png',
  165. 'gif')))) {
  166. $error = $this->__('Error deleting avatar');
  167. }
  168. //delete the small picture
  169. ModUtil::func('IWusers', 'user', 'deleteAvatar', array('avatarName' => substr($chid, 0, -4) . '_s',
  170. 'extensions' => array('jpg',
  171. 'png',
  172. 'gif')));
  173. if (!ModUtil::apiFunc('IWusers', 'user', 'changeAvatar', array('avatar' => '',
  174. 'target' => 'newavatar',
  175. 'uid' => $uid,
  176. )))
  177. $error = $this->__('Changing the avatar has failed.');
  178. } else {
  179. $file_extension = strtolower(substr(strrchr($chid, "."), 1));
  180. $formats = '$jpg$$png$$gif$';
  181. $formats = str_replace('$' . $file_extension . '$', '', $formats);
  182. $len = strlen($formats) - 2;
  183. $formatsArray = explode('$$', substr($formats, 1, $len));
  184. //change file name
  185. $changed = rename($path . $chid, $path . substr($chid, 1, strlen($chid)));
  186. if ($changed) {
  187. ModUtil::func('IWusers', 'user', 'deleteAvatar', array('avatarName' => substr($chid, 1, -4),
  188. 'extensions' => $formatsArray));
  189. } else {
  190. $error = $this->__('Error changing avatar');
  191. }
  192. //Change small pictures
  193. $chid_s = substr($chid, 0, -4) . '_s.' . $file_extension;
  194. rename($path . $chid_s, $path . substr($chid_s, 1, strlen($chid_s)));
  195. ModUtil::func('IWusers', 'user', 'deleteAvatar', array('avatarName' => substr($chid_s, 1, -4),
  196. 'extensions' => $formatsArray));
  197. if (!ModUtil::apiFunc('IWusers', 'user', 'changeAvatar', array('avatar' => '',
  198. 'target' => 'newavatar',
  199. 'uid' => $uid,
  200. )))
  201. $error = $this->__('Changing the avatar has failed.');
  202. if (!ModUtil::apiFunc('IWusers', 'user', 'changeAvatar', array('avatar' => $userAvatar,
  203. 'uid' => $uid,
  204. )))
  205. $error = $this->__('Changing the avatar has failed.');
  206. }
  207. $sv = ModUtil::func('IWmain', 'user', 'genSecurityValue');
  208. ModUtil::func('IWmain', 'user', 'userSetVar', array('module' => 'IWmain_block_news',
  209. 'name' => 'have_news',
  210. 'value' => 'ch',
  211. 'sv' => $sv));
  212. AjaxUtil::output(array('chid' => $userAvatar,
  213. 'error' => $error));
  214. }
  215. }