/** * JSON request to insert a new value into an option table (used for dynamic drop-downs and adding a dynamic checkbox) */ public function insertTableAction() { $request = $this->getRequest(); if ($request->isXmlHttpRequest()) { $table = $this->getSanParam('table'); $column = $this->getSanParam('column'); $value = $this->getSanParam('value'); if ($table && $column && $value) { $tableObj = new ITechTable(array('name' => $table)); $undelete = $this->getSanParam('undelete'); if ($undelete) { try { $row = $tableObj->undelete($column, $value); $sendRay['insert'] = $row->id; $this->sendData($sendRay); } catch (Zend_Exception $e) { $this->sendData(array("insert" => 0, 'error' => $e->getMessage())); } } else { // Attempt to insert new try { $insert = $tableObj->insertUnique($column, $value); $sendRay['insert'] = "{$insert}"; if ($insert == -1) { $sendRay['error'] = '"%s" ' . t('already exists') . '.'; } if ($insert == -2) { $sendRay['error'] = '"%s" ' . 'already exists, but was deleted. Would you like to undelete?'; } // associate new training title with training category if ($table == 'training_title_option' && !isset($sendRay['error']) && ($cat_id = $this->getSanParam('cat_id'))) { $tableCatObj = new ITechTable(array('name' => 'training_category_option_to_training_title_option')); $tableCatObj->insert(array('training_category_option_id' => $cat_id, 'training_title_option_id' => $insert)); } $this->sendData($sendRay); } catch (Zend_Exception $e) { $this->sendData(array("insert" => 0, 'error' => $e->getMessage())); error_log($e); } } } } }