public function newEvent($start, $end, $title, $description, $location, $categories, $access, $allDay) { if (!empty($this->user_id) && !empty($this->table)) { jqGridDB::beginTransaction($this->db); $query = jqGridDB::prepare($this->db, "INSERT INTO " . $this->table . "\t(user_id, start, end, title, description, location, categories, access, all_day)\n\t\t\tVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", array($this->user_id, $start, $end, $title, $description, $location, $categories, $access, $allDay)); jqGridDB::execute($query); $lastid = jqGridDB::lastInsertId($this->db, $this->table, 'event_id', $this->dbtype); jqGridDB::commit($this->db); jqGridDB::closeCursor($query); return $lastid; } else { return false; } }
/** * * Delete the data into the database according the table element * A primaryKey should be set. If the key is not set It can be obtained * from jqGridDB::getPrimaryKey * Return true on success, false when the operation is not succefull * @todo possibility to set additional where clause * @param array $data associative array which key values correspond to the * names in the delete command * @return boolean */ public function delete(array $data, $where = '', array $params = null) { $result = false; if (!$this->del) { return $result; } //SQL Server hack if (!$this->checkPrimary()) { return $result; } $ide = null; $binds = array(&$ide); $types = array(); if (count($data) > 0) { if ($where && strlen($where) > 0) { $id = ""; $sql = "DELETE FROM " . $this->table . " WHERE " . $where; $stmt = $this->parseSql($sql, $params); $delids = ""; $custom = true; } else { $id = $this->getPrimaryKeyId(); if (!isset($data[$id])) { $this->errorMessage = "Missed data id value to perform delete!"; if ($this->showError) { $this->sendErrorHeader(); } return $result; } $sql = "DELETE FROM " . $this->table . " WHERE " . $id . "=?"; $stmt = $this->parseSql($sql, $binds, false); $delids = explode(",", $data[$id]); $custom = false; } $types[0] = 'custom'; if ($stmt) { if ($this->trans) { try { jqGridDB::beginTransaction($this->pdo); $result = $this->_actionsCRUDGrid('del', 'before'); if ($custom) { if ($this->debug) { $this->logQuery($sql, $params, false, $data, null, $this->primaryKey); } $result = jqGridDB::execute($stmt, $params); } else { foreach ($delids as $i => $ide) { $delids[$i] = trim($delids[$i]); $binds[0] =& $delids[$i]; if ($this->debug) { $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey); } jqGridDB::bindValues($stmt, $binds, $types); $result = jqGridDB::execute($stmt, $binds); if (!$result) { break; } unset($binds[0]); } } jqGridDB::closeCursor($stmt); if ($result) { $result = $this->_actionsCRUDGrid('del', 'after'); } if ($result) { jqGridDB::commit($this->pdo); } else { $this->errorMessage = jqGridDB::errorMessage($this->pdo); throw new Exception($this->errorMessage); } } catch (Exception $e) { jqGridDB::rollBack($this->pdo); $result = false; if (!$this->errorMessage) { $this->errorMessage = $e->getMessage(); } } } else { try { $result = $this->_actionsCRUDGrid('del', 'before'); if ($result) { if ($custom) { $result = jqGridDB::execute($stmt, $params); } else { foreach ($delids as $i => $ide) { $delids[$i] = trim($delids[$i]); $binds[0] =& $delids[$i]; if ($this->debug) { $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey); } jqGridDB::bindValues($stmt, $binds, $types); $result = jqGridDB::execute($stmt, $binds); if (!$result) { break; } unset($binds[0]); } } } jqGridDB::closeCursor($stmt); if ($result) { $result = $this->_actionsCRUDGrid('del', 'after'); } if (!$result) { $this->errorMessage = jqGridDB::errorMessage($this->pdo); throw new Exception($this->errorMessage); } } catch (Exception $e) { $result = false; if (!$this->errorMessage) { $this->errorMessage = $e->getMessage(); } } } } } if ($this->debug) { $this->debugout(); } if ($this->showError && !$result) { $this->sendErrorHeader(); } return $result; }
public function delete(array $data) { $result = false; if (!$this->del) { return $result; } $ide = null; $binds = array(&$ide); $types = array(); if (count($data) > 0) { $id = $this->getPrimaryKeyId(); if (!isset($data[$id])) { return $result; } $sql = "DELETE FROM " . $this->table . " WHERE " . $id . "=?"; $stmt = $this->parseSql($sql, $binds, false); $delids = explode(",", $data[$id]); $types[0] = 'custom'; if ($stmt) { if ($this->trans) { jqGridDB::beginTransaction($this->pdo); foreach ($delids as $i => $ide) { $delids[$i] = trim($delids[$i]); $binds[0] =& $delids[$i]; if ($this->debug) { $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey); } jqGridDB::bindValues($stmt, $binds, $types); $test = jqGridDB::execute($stmt, $binds); if (!$test) { jqGridDB::rollBack($this->pdo); break; $result = false; } unset($binds[0]); } if ($test) { $result = jqGridDB::commit($this->pdo); } } else { foreach ($delids as $i => $ide) { $delids[$i] = trim($delids[$i]); $binds[0] =& $delids[$i]; if ($this->debug) { $this->logQuery($sql, $binds, $types, $data, $this->fields, $this->primaryKey); } jqGridDB::bindValues($stmt, $binds, $types); $test = jqGridDB::execute($stmt, $binds); if (!$test) { break; $result = false; } unset($binds[0]); } $result = true; } jqGridDB::closeCursor($stmt); } } if ($this->debug) { $this->debugout(); } return $result; }
public function newEvent($data = array()) { //$start, $end, $title, $description, $location, $categories, $access, $allDay) { if (!empty($this->user_id) && !empty($this->table)) { if (!isset($data['user_id'])) { return false; } if (is_array($this->user_id)) { if (!in_array($data['user_id'], $this->user_id)) { return false; } } else { if ($data['user_id'] != $this->user_id) { return false; } } $tableFields = array_keys($this->dbmap); $binds = array(); unset($tableFields['event_id']); $rowFields = array_intersect($tableFields, array_keys($data)); foreach ($rowFields as $key => $val) { $insertFields[] = "?"; //$field; $value = $data[$val]; if (strtolower($this->encoding) != 'utf-8') { $value = iconv("utf-8", $this->encoding . "//TRANSLIT", $value); } $binds[] = $value; } $sql = ""; if (count($insertFields) > 0) { $sql = "INSERT INTO " . $this->table . " (" . implode(', ', $rowFields) . ")" . " VALUES( " . implode(', ', $insertFields) . ")"; } if (!$sql) { return false; } jqGridDB::beginTransaction($this->db); $query = jqGridDB::prepare($this->db, $sql, $binds); jqGridDB::execute($query); $lastid = jqGridDB::lastInsertId($this->db, $this->table, 'event_id', $this->dbtype); jqGridDB::commit($this->db); jqGridDB::closeCursor($query); return $lastid; } else { return false; } }