PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/workflow/engine/methods/authSources/authSources_Ajax.php

https://bitbucket.org/ferOnti/processmaker
PHP | 190 lines | 152 code | 11 blank | 27 comment | 23 complexity | 674bf3b30652c8eed02fb4bf6631e608 MD5 | raw file
  1. <?php
  2. /**
  3. * authSources_Ajax.php
  4. *
  5. * ProcessMaker Open Source Edition
  6. * Copyright (C) 2004 - 2011 Colosa Inc.23
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  22. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  23. */
  24. try {
  25. global $RBAC;
  26. if ($RBAC->userCanAccess( 'PM_SETUP_ADVANCE' ) != 1) {
  27. G::SendTemporalMessage( 'ID_USER_HAVENT_RIGHTS_PAGE', 'error', 'labels' );
  28. G::header( 'location: ../login/login' );
  29. die();
  30. }
  31. switch ($_REQUEST['action']) {
  32. case 'searchUsers':
  33. require_once 'classes/model/Users.php';
  34. $criteria = new Criteria( 'workflow' );
  35. $criteria->addSelectColumn( UsersPeer::USR_USERNAME );
  36. $criteria->add( UsersPeer::USR_STATUS, array ('CLOSED'
  37. ), Criteria::NOT_IN );
  38. $dataset = UsersPeer::DoSelectRs( $criteria );
  39. $dataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  40. $dataset->next();
  41. $pmUsers = array ();
  42. while ($row = $dataset->getRow()) {
  43. $pmUsers[] = $row['USR_USERNAME'];
  44. $dataset->next();
  45. }
  46. $aFields = $RBAC->getAuthSource( $_POST['sUID'] );
  47. G::LoadThirdParty( 'pear/json', 'class.json' );
  48. $oJSON = new Services_JSON();
  49. $i = 0;
  50. $oUser = new Users();
  51. $aAux = $RBAC->searchUsers( $_POST['sUID'], $_POST['sKeyword'] );
  52. $aUsers = array ();
  53. // note added by gustavo cruz gustavo-at-colosa.com
  54. // changed the user data showed to accept FirstName and LastName variables
  55. $aUsers[] = array ('Checkbox' => 'char','Username' => 'char','FullName' => 'char','FirstName' => 'char','LastName' => 'char','Email' => 'char','DistinguishedName' => 'char'
  56. );
  57. foreach ($aAux as $aUser) {
  58. if (! in_array( $aUser['sUsername'], $pmUsers )) {
  59. // add replace to change D'Souza to D*Souza by krlos
  60. $sCheckbox = '<div align="center"><input type="checkbox" name="aUsers[' . $i . ']" id="aUsers[' . $i . ']" value=\'' . str_replace( "\'", "*", addslashes( $oJSON->encode( $aUser ) ) ) . '\' /></div>';
  61. $i ++;
  62. } else {
  63. $sCheckbox = G::LoadTranslation( 'ID_USER_REGISTERED' ) . ':<br />(' . $aUser['sUsername'] . ')';
  64. }
  65. // note added by gustavo cruz gustavo-at-colosa.com
  66. // assign the user data to the DBArray variable.
  67. $aUsers[] = array ('Checkbox' => $sCheckbox,'Username' => $aUser['sUsername'],'FullName' => $aUser['sFullname'],'FirstName' => $aUser['sFirstname'],'LastName' => $aUser['sLastname'],'Email' => $aUser['sEmail'],'DistinguishedName' => $aUser['sDN']
  68. );
  69. }
  70. global $_DBArray;
  71. $_DBArray['users'] = $aUsers;
  72. $_SESSION['_DBArray'] = $_DBArray;
  73. G::LoadClass( 'ArrayPeer' );
  74. $oCriteria = new Criteria( 'dbarray' );
  75. $oCriteria->setDBArrayTable( 'users' );
  76. $aData = Array ('Checkbox' => '0','FullName' => '0'
  77. );
  78. global $G_PUBLISH;
  79. $G_PUBLISH = new Publisher();
  80. if ($aFields['AUTH_SOURCE_PROVIDER'] != 'ldap') {
  81. $G_PUBLISH->AddContent( 'propeltable', 'pagedTableLdap', 'authSources/ldapSearchResults', $oCriteria, ' ', array ('Checkbox' => G::LoadTranslation( 'ID_MSG_CONFIRM_DELETE_CASE_SCHEDULER' )
  82. ) );
  83. } else {
  84. if (file_exists( PATH_XMLFORM . 'authSources/' . $aFields['AUTH_SOURCE_PROVIDER'] . 'Edit.xml' )) {
  85. $G_PUBLISH->AddContent( 'propeltable', 'pagedTableLdap', 'authSources/' . $aFields['AUTH_SOURCE_PROVIDER'] . 'SearchResults', $oCriteria, ' ', array ('Checkbox' => G::LoadTranslation( 'ID_MSG_CONFIRM_DELETE_CASE_SCHEDULER' )
  86. ) );
  87. } else {
  88. $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', array ('MESSAGE' => 'File: ' . $aFields['AUTH_SOURCE_PROVIDER'] . 'SearchResults.xml' . ' doesn\'t exist.'
  89. ) );
  90. }
  91. }
  92. G::RenderPage( 'publish', 'raw' );
  93. break;
  94. case 'authSourcesList':
  95. require_once PATH_RBAC . 'model/AuthenticationSource.php';
  96. global $RBAC;
  97. G::LoadClass( 'configuration' );
  98. $co = new Configurations();
  99. $config = $co->getConfiguration( 'authSourcesList', 'pageSize', '', $_SESSION['USER_LOGGED'] );
  100. $limit_size = isset( $config['pageSize'] ) ? $config['pageSize'] : 20;
  101. $start = isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : 0;
  102. $limit = isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : $limit_size;
  103. $filter = isset( $_REQUEST['textFilter'] ) ? $_REQUEST['textFilter'] : '';
  104. $Criterias = $RBAC->getAuthenticationSources( $start, $limit, $filter );
  105. $Dat = AuthenticationSourcePeer::doSelectRS( $Criterias['COUNTER'] );
  106. $Dat->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  107. $Dat->next();
  108. $row = $Dat->getRow();
  109. $total_sources = $row['CNT'];
  110. $oDataset = AuthenticationSourcePeer::doSelectRS( $Criterias['LIST'] );
  111. $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  112. global $RBAC;
  113. $auth = $RBAC->getAllUsersByAuthSource();
  114. $aSources = Array ();
  115. while ($oDataset->next()) {
  116. $aSources[] = $oDataset->getRow();
  117. $index = sizeof( $aSources ) - 1;
  118. $aSources[$index]['CURRENT_USERS'] = isset( $auth[$aSources[$index]['AUTH_SOURCE_UID']] ) ? $auth[$aSources[$index]['AUTH_SOURCE_UID']] : 0;
  119. }
  120. echo '{sources: ' . G::json_encode( $aSources ) . ', total_sources: ' . $total_sources . '}';
  121. break;
  122. case 'canDeleteAuthSource':
  123. try {
  124. $authUID = $_POST['auth_uid'];
  125. global $RBAC;
  126. $aAuth = $RBAC->getAllUsersByAuthSource();
  127. $response = isset( $aAuth[$authUID] ) ? 'false' : 'true';
  128. echo '{success: ' . $response . '}';
  129. } catch (Exception $ex) {
  130. echo '{success: false, error: ' . $ex->getMessage() . '}';
  131. }
  132. break;
  133. case 'deleteAuthSource':
  134. try {
  135. global $RBAC;
  136. $RBAC->removeAuthSource( $_POST['auth_uid'] );
  137. echo '{success: true}';
  138. } catch (Exception $ex) {
  139. echo '{success: false, error: ' . $ex->getMessage() . '}';
  140. }
  141. break;
  142. case 'authSourcesNew':
  143. $arr = Array ();
  144. $oDirectory = dir( PATH_RBAC . 'plugins' . PATH_SEP );
  145. $aAuthSourceTypes = array ();
  146. while ($sObject = $oDirectory->read()) {
  147. if (($sObject != '.') && ($sObject != '..') && ($sObject != '.svn') && ($sObject != 'ldap')) {
  148. if (is_file( PATH_RBAC . 'plugins' . PATH_SEP . $sObject )) {
  149. $sType = trim( str_replace( 'class.', '', str_replace( '.php', '', $sObject ) ) );
  150. $aAuthSourceTypes['sType'] = $sType;
  151. $aAuthSourceTypes['sLabel'] = $sType;
  152. $arr[] = $aAuthSourceTypes;
  153. }
  154. }
  155. }
  156. echo '{sources: ' . G::json_encode( $arr ) . '}';
  157. break;
  158. case 'loadauthSourceData':
  159. global $RBAC;
  160. $fields = $RBAC->getAuthSource( $_POST['sUID'] );
  161. if (is_array( $fields['AUTH_SOURCE_DATA'] )) {
  162. foreach ($fields['AUTH_SOURCE_DATA'] as $field => $value) {
  163. $fields[$field] = $value;
  164. }
  165. }
  166. unset( $fields['AUTH_SOURCE_DATA'] );
  167. $result->success = true;
  168. $result->sources = $fields;
  169. print (G::json_encode( $result )) ;
  170. break;
  171. }
  172. } catch (Exception $e) {
  173. $fields = array ('MESSAGE' => $e->getMessage()
  174. );
  175. global $G_PUBLISH;
  176. $G_PUBLISH = new Publisher();
  177. $G_PUBLISH->AddContent( 'xmlform', 'xmlform', 'login/showMessage', '', $fields );
  178. G::RenderPage( 'publish', 'blank' );
  179. }