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'); } }