Example #1
0
 public function EditRecord()
 {
     $this->isReadonly();
     $this->setDB();
     $this->setCollection();
     $id = $this->request->getParam('id');
     $idType = $this->request->getParam('id_type');
     $format = $this->request->getParam('format');
     $cryptography = new Cryptography();
     $model = $this->getModel();
     if ($this->request->isPost()) {
         if ($this->request->getParam('format') == 'array') {
             $data = $cryptography->stringToArray($this->request->getParam('data'));
             if (is_array($data)) {
                 $response = $model->updateById($this->db, $this->collection, $id, $data, 'array', $idType);
             } else {
                 $response['errmsg'] = I18n::t('INVALID_DATA');
             }
         } else {
             if ($this->request->getParam('format') == 'json') {
                 $response = $model->updateById($this->db, $this->collection, $id, $this->request->getParam('data'), 'json', $idType);
             }
         }
         if (isset($response['ok']) && $response['ok'] == 1) {
             $this->message->sucess = I18n::t('U_S');
         } else {
             $this->message->error = $response['errmsg'];
         }
     }
     if (!empty($this->db) && !empty($this->collection) && !empty($id) && !empty($idType)) {
         $cursor = $model->findById($this->db, $this->collection, $id, $idType);
         if ($cursor) {
             unset($cursor['_id']);
             $record['json'] = $cryptography->arrayToJSON($cursor);
             $record['array'] = $cryptography->arrayToString($cursor);
             $this->application->view = 'Collection';
             $this->display('edit', array('record' => $record, 'format' => $format, 'id' => $id));
         } else {
             $this->message->error = I18n::t('INVALID_ID');
         }
     } else {
         $this->url = "index.php";
         $this->request->redirect($this->url);
     }
 }