Esempio n. 1
0
 public function delete()
 {
     $params = $this->input->post('params');
     if (!is_array($params) || count($params) == 0) {
         $this->returnError('Some information are missing');
     }
     //TODO translate with CI standard way
     extract($params);
     //
     //     	if(isset($params['procedure'])) $procedure = urlencode(trim($params['procedure']));
     //     	if(isset($params['object_name'])) $object_name = urlencode(trim($params['object_name']));
     //     	if(isset($params['object_id'])) $object_id = urlencode(trim($params['object_id']));
     switch ($procedure) {
         case 'deleteLocation':
             if (!isset($object_name) || !isset($object_id)) {
                 $this->returnError('Some information are missing');
             }
             if (strtolower($object_name) != 'location') {
                 $this->returnError('The specified ' . $object_name . ' can not be deleted.');
             }
             $location = new Mdl_Location();
             $location->locId = $object_id;
             $input = array();
             $input['locId'] = $object_id;
             if ($location->delete($input)) {
                 $to_js = array();
                 $to_js['message'] = 'The location has been deleted.';
                 $to_js['focus_tab'] = '#tab_locations';
             } else {
                 $this->returnError('The location has not been deleted');
             }
             break;
         case 'deleteOrganizationMembership':
             if (!isset($object_name) || !isset($object_id) || !isset($related_object_name) || !isset($related_object_id)) {
                 $this->returnError('Some information are missing');
             }
             if (strtolower($object_name) != 'organization') {
                 $this->returnError('The specified object_name ' . $object_name . ' can not be used in this procedure.');
             }
             //get the person
             $person = new Mdl_Person();
             $person->uid = $related_object_id;
             $result = $person->get(null);
             if ($result['status']['status_code'] == '200' && $result['status']['results_number'] == '1') {
                 //get the organization
                 $organization = new Mdl_Organization();
                 $organization->oid = $object_id;
                 $res = $organization->get();
                 if ($res['status']['status_code'] == '200' && $result['status']['results_number'] == '1') {
                     $organization->arrayToObject($res['data']['0']);
                     $organization_name = $organization->o;
                 } else {
                     $this->returnError('The selected organization can not be found');
                 }
                 //update person's attributes
                 $person->arrayToObject($result['data']['0']);
                 $ordn = explode(',', $person->oRDN);
                 foreach ($ordn as $key => $item) {
                     if ($item == $object_id) {
                         unset($ordn[$key]);
                     }
                 }
                 if (count($ordn) > 0) {
                     $person->oRDN = implode(',', $ordn);
                 } else {
                     $person->oRDN = '';
                 }
                 $oAdminRDN = explode(',', $person->oAdminRDN);
                 foreach ($oAdminRDN as $key => $item) {
                     if ($item == $object_id) {
                         unset($oAdminRDN[$key]);
                     }
                 }
                 if (count($oAdminRDN) > 0) {
                     $person->oAdminRDN = implode(',', $oAdminRDN);
                 } else {
                     $person->oAdminRDN = '';
                 }
                 $o = explode(',', $person->o);
                 foreach ($o as $key => $item) {
                     if ($item == $organization_name) {
                         unset($o[$key]);
                     }
                 }
                 if (count($o) > 0) {
                     $person->o = implode(',', $o);
                 } else {
                     $person->o = '';
                 }
                 if ($person->save(false)) {
                     $to_js = array();
                     $to_js['message'] = $person->cn . " has been disassociated from " . $organization_name;
                     $to_js['focus_tab'] = '#tab_memberOf';
                 } else {
                     $this->returnError('The association process failed.');
                 }
             }
             break;
         default:
             $this->returnError('An invalid procedure has been requested');
             break;
     }
     if (isset($to_js)) {
         $this->output($to_js);
     } else {
         $this->returnError('Something went wrong');
     }
 }
Esempio n. 2
0
 /**
  * This function is called by the javascript (System Settings) everytime there is an event (drag, sort, submit)
  * It updates the config file for the specific object and returns the updated html to the javascript which
  * replaces the old content with the new one   
  * 
  * @access		private
  * @param
  * @return		string		
  * @example
  * @see
  * 
  * @author 		Damiano Venturin
  * @copyright 	2V S.r.l.
  * @license		GPL
  * @link		http://www.squadrainformatica.com/en/development#mcbsb  MCB-SB official page
  * @since		Feb 6, 2012
  *
  */
 public function update_settings()
 {
     $output = '';
     $data = array();
     $split = preg_split('/_/', $this->input->post('action'));
     if (isset($split['0'])) {
         $objName = $split['0'];
     }
     if (isset($split['1'])) {
         $action = $split['1'];
     }
     switch ($objName) {
         case 'person':
             $obj = new Mdl_Person();
             break;
         case 'organization':
             $obj = new Mdl_Organization();
             break;
         case 'location':
             $obj = new Mdl_Location();
             break;
         default:
             return false;
             break;
     }
     $obj->getProperties();
     $obj->prepareShow();
     $tpl = null;
     switch ($action) {
         case 'addToVisible':
             if ($attribute = $this->getAjaxItem()) {
                 $this->toVisible($obj, 'add', $attribute);
             }
             break;
         case 'removeFromVisible':
             if ($attribute = $this->getAjaxItem()) {
                 $this->toVisible($obj, 'remove', $attribute);
             }
             break;
         case 'sort':
             //show_fields is the ordered array of fields coming from the accordion
             $show_fields = $this->input->post(ucfirst(strtolower($objName)) . 'VisibleAttributes');
             if (is_array($show_fields)) {
                 if (is_array($obj->show_fields)) {
                     //let's check if the given array (show_fields) is not fake
                     if (count(array_diff($obj->show_fields, $show_fields)) == 0) {
                         //there are no differences so I can assume that the POST wasn't manipulated
                         $obj->show_fields = $show_fields;
                         $this->update_config($obj, $obj->objName);
                     }
                 }
             }
             $tpl = 'order';
             break;
         case 'aliases':
             if ($this->input->post('save')) {
                 if (is_array($this->input->post('form'))) {
                     $aliases = array();
                     $form = $this->input->post('form');
                     foreach ($form as $key => $item) {
                         if (!empty($item['value']) and $item['type'] == 'TEXT') {
                             $aliases[$item['field']] = strtolower(only_chars_nums_underscore($item['value']));
                         }
                     }
                     $obj->aliases = $aliases;
                     $this->update_config($obj, $obj->objName);
                 }
             }
             $tpl = 'aliases';
             break;
     }
     echo $this->display_object_settings($obj, $tpl);
 }