protected function deleteUpload($uid) { $additionalQuerys = $this->deleteQuerysCreateAdditional($uid); TableMng::getDb()->autocommit(false); TableMng::queryMultiple("DELETE FROM SystemUsers WHERE ID = {$uid};\n\t\t\t{$additionalQuerys}\n\t\t\t"); TableMng::getDb()->autocommit(true); }
/** * Deletes the Message with the Id $messageId * Also deletes all entries in the tables MessageReceivers and * MessageManagers that are linked to this Message * @param id $messageId the message to delete * @throws Exception if somethings gone wrong */ public static function deleteMessage($messageId) { $db = TableMng::getDb(); $db->autocommit(false); $query = sprintf('DELETE FROM MessageMessages WHERE `ID` = %s; DELETE FROM MessageReceivers WHERE `messageId` = %s; DELETE FROM MessageManagers WHERE `messageId` = %s;', $messageId, $messageId, $messageId); TableMng::queryMultiple($query); $db->autocommit(true); }
/** * Uploads the Meal-Order to the Database * * @param int $userId The Id of the User that ordered the Meal * @param string $ip The IP of the User */ protected function orderToDb($userId, $ip) { $meal = $this->_meal; $ordertime = date("Y-m-d h:i:s"); $soliPrice = $this->soliPriceGet(); TableMng::query("INSERT INTO BabeskOrders\n\t\t\t(MID, UID, date, IP, ordertime, fetched) VALUES\n\t\t\t('{$meal['ID']}', '{$userId}', '{$meal['date']}', '{$ip}', '{$ordertime}', 0)"); $lastInsertId = TableMng::getDb()->insert_id; if ($this->_hasValidCoupon) { TableMng::query("INSERT INTO BabeskSoliOrders (ID, UID, date, IP,\n\t\t\t\tordertime, fetched, mealname, mealprice, mealdate, soliprice)\n\t\t\t\tVALUES ('{$lastInsertId}', '{$userId}', '{$meal['date']}', '{$ip}',\n\t\t\t\t\t'{$ordertime}', '0', '{$meal['name']}', '{$meal['price']}',\n\t\t\t\t\t'{$meal['date']}', '{$soliPrice}')"); } }
/** * Processes the data and uploads them to the Db. On error, nothing gets * comitted */ protected static function upload() { TableMng::getDb()->autocommit(false); $stmt = TableMng::getDb()->prepare('INSERT INTO `BabeskSoliOrders` (`ID`, `UID`, `date`, `IP`, `ordertime`, `fetched`, `mealname`, `mealprice`, `mealdate`, `soliprice`) VALUES (?, ?, ?, "", ?, ?, ?, ?, ?, ?)'); foreach (self::$_soliData as $order) { if (self::soliDataCheck($order)) { $price = isset(self::$_soliprice) && self::$_soliprice != '' ? self::$_soliprice : 0; $stmt->bind_param('sssssssss', $order['orderId'], $order['userId'], $order['mealdate'], $order['ordertime'], $order['fetched'], $order['mealname'], $order['price'], $order['mealdate'], $price); if ($stmt->execute()) { //good for us } else { echo $stmt->error; throw new Exception('Could not execute an upload successfully'); } } } $stmt->close(); TableMng::getDb()->autocommit(true); }
/** * Stores the Attributes of the Temporary file to the Database * * @return [type] [description] */ protected function storeToDb() { //only create new entry when entry is not existing already if ($this->_fileId === false) { try { TableMng::query("INSERT INTO SystemTemporaryFiles\n\t\t\t\t\t\t(`location`, `created`, `until`, `usage`)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t('', '{$this->_created}', '{$this->_until}', '{$this->_usage}');\n\t\t\t\t\t\t"); $this->_fileId = TableMng::getDb()->insert_id; $this->filepathCreate(); //Update the location since only now we know the ID of the file $this->_filepath = addslashes($this->_filepath); TableMng::query("UPDATE SystemTemporaryFiles\n\t\t\t\t\tSET `location` = '{$this->_filepath}'\n\t\t\t\t\tWHERE ID = {$this->_fileId}"); } catch (Exception $e) { throw new TemporaryFileException('Could not insert data into Database' . $e->getMessage(), 2); } } else { throw new TemporaryFileException("The Element with ID {$this->_fileId} already exists in the Database"); } }
protected function delete() { if (isset($_GET['ID'])) { $id = TableMng::getDb()->real_escape_string($_GET['ID']); if (isset($_POST['nonono'])) { $this->_interface->dieMsg('Der Schultyp wurde nicht gelöscht'); } else { if (isset($_POST['deletePls'])) { $this->dbDeleteFrom($id); $this->_interface->dieMsg('Der Schultyp wurde erfolgreich gelöscht'); } else { $schooltype = $this->fetch($id); $this->_interface->deleteSchooltype($schooltype); } } } }
/** * Cancels the Order and repays the money to the User */ protected function orderCancel() { $this->_isSoli = $this->userHasValidCoupon(); $this->_isSolipriceEnabled = $this->isSolipriceEnabledGet(); try { $amount = $this->amountToRepayGet(); TableMng::getDb()->autocommit(false); $this->repay($amount); $this->orderDbEntryDelete($this->_orderData['ID']); TableMng::getDb()->autocommit(true); } catch (Exception $e) { $this->_interface->dieError('Konnte die Bestellung nicht abbrechen' . $e->getMessage()); } }
/** * Deletes the Grade and all Linked Tableentrys from the Database */ protected function submoduleDeleteGradeExecute() { TableMng::sqlEscape($_GET['ID']); TableMng::getDb()->autocommit(false); $this->deleteGradeFromDatabase(); $this->deleteLinkedItems($_GET['ID']); TableMng::getDb()->autocommit(true); $this->_interface->dieMsg(_g('The Grade was successfully deleted')); }
/** * Deletes a Template from the Database based on the ID the user has given */ protected function templateDelete() { $id = TableMng::getDb()->real_escape_string($_GET['id']); $this->templateDeleteFromDb($id); $this->_interface->dieMsg('Die Vorlage wurde erfolgreich gelöscht'); }
protected function additionalUserQuerysInit() { $this->_stmtSchoolyearAndGrade = TableMng::getDb()->prepare('INSERT INTO SystemAttendances (userId, gradeId, schoolyearId) VALUES (?, ?, ?)'); $this->_stmtUsergroups = $this->_pdo->prepare('INSERT INTO SystemUsersInGroups (userId, groupId) VALUES (:userId, :groupId);'); $this->_noGradeId = $this->noGradeIdGet(); }
/** * Finalizes the Data-Upload. Ends Transaction and, on certain * circumstances, rolls the changes back */ protected function uploadFinalize() { if ($this->_isPreview) { TableMng::getDb()->query('ROLLBACK'); $this->_pdo->rollBack(); } else { if (!count($this->_errors)) { TableMng::getDb()->query('COMMIT'); $this->_pdo->commit(); return true; } else { TableMng::getDb()->query('ROLLBACK'); $this->_pdo->rollBack(); $this->errorDie(_g('Could not upload the CSV-File!')); } } TableMng::getDb()->autocommit(true); return false; }
/** * Processes the data and uploads them to the Db. On error, nothing gets * comitted */ protected static function upload() { TableMng::getDb()->autocommit(false); $chargeArr = array(); $stmt = TableMng::getDb()->prepare('INSERT INTO `BabeskSoliOrders` (`ID`, `UID`, `date`, `IP`, `ordertime`, `fetched`, `mealname`, `mealprice`, `mealdate`, `soliprice`) VALUES (?, ?, ?, "", ?, ?, ?, ?, ?, ?)'); foreach (self::$_soliData as $order) { if (self::soliDataCheck($order)) { $price = self::solipriceFetch($order['pc_ID']); $stmt->bind_param('sssssssss', $order['orderId'], $order['userId'], $order['mealdate'], $order['ordertime'], $order['fetched'], $order['mealname'], $order['price'], $order['mealdate'], $price); if ($stmt->execute()) { //good for us } else { echo $stmt->error; throw new Exception('Could not execute an upload successfully'); } $userRep = self::$_em->getRepository("DM:SystemUsers"); $user = $userRep->findOneById($order['userId']); $curAmount = $user->getCredit(); $diff = $order['price'] - $price; $user->setCredit($curAmount + $diff); if (isset($chargeArr[$order['userId']])) { $chargeArr[$order['userId']] += $diff; } else { $chargeArr[$order['userId']] = $diff; } } } /** *Uncomment this to get the recharges as an extra SQL-Statement * *foreach ($chargeArr as $key => $value){ * file_put_contents("recharge_credit_sql.txt", "UPDATE systemusers SET credit = credit + ".$value." WHERE ID = ".$key.";\r\n", FILE_APPEND); *} */ $stmt->close(); self::$_em->persist($user); self::$_em->flush(); TableMng::getDb()->autocommit(true); }
protected function fetchTextsAjax() { $templateId = TableMng::getDb()->real_escape_string($_POST['templateId']); $textId = TableMng::getDb()->real_escape_string($_POST['textId']); try { $template = TableMng::query(sprintf('SELECT * FROM SchbasTexts WHERE `description` = "%s%s"', $textId, $templateId)); } catch (Exception $e) { die('errorFetchTemplate'); } die(json_encode($template[0])); }
/** * Adds a new group to the DatabaseTable * * Requirement: the Parent has childs * * @param String $name The name of the new Group * @param String $parentName The name of the parent-Group * @todo if multiple parents with this name exist, problem! */ protected static function groupAddToNodeWithChildren($name, $parentName) { TableMng::getDb()->autocommit(false); TableMng::queryMultiple("SELECT @myRight := rgt FROM SystemGroups\n\t\t\tWHERE name = '{$parentName}';\n\t\t\tUPDATE SystemGroups SET rgt = rgt + 2 WHERE rgt >= @myRight;\n\t\t\tUPDATE SystemGroups SET lft = lft + 2 WHERE lft >= @myRight;\n\t\t\tINSERT INTO SystemGroups(name, lft, rgt) VALUES('{$name}',\n\t\t\t\t\t\t\t@myRight, @myRight + 1);\n\t\t\t"); TableMng::getDb()->autocommit(true); }
/** * based on the post-values given from Ajax, this function sets the * has-user-returned-the-message-value to "hasReturned" * * @return void */ protected function userSetReturnedMsgByButtonAjax() { $mid = TableMng::getDb()->real_escape_string($_POST['messageId']); $uid = TableMng::getDb()->real_escape_string($_POST['userId']); $this->userSetReturnedMsg($mid, $uid); }
/** * Removes a Message from the Database by the ID given * * It also removes the links to this Message in the Tables * MessageReceivers and MessageManagers. * * @param int $id the ID of the message to remove */ protected function messageDeleteFromDb($id) { try { TableMng::getDb()->autocommit(false); $query = sprintf('DELETE FROM MessageMessages WHERE `ID` = %s; DELETE FROM MessageReceivers WHERE `messageId` = %s; DELETE FROM MessageManagers WHERE `messageId` = %s;', $id, $id, $id); TableMng::queryMultiple($query); TableMng::getDb()->autocommit(true); } catch (Exception $e) { $this->_interface->dieError('Konnte die Nachricht nicht löschen!'); } }
/** * Changes the global Setting messageEditGroupId to the $newGroupId * * dies when error occured while changing the group * * @param int $newGroupId the Id of the new group thats allowed to edit * Messages */ protected function authorGroupChangeCommit($newGroupId) { try { TableMng::query(sprintf('UPDATE SystemGlobalSettings SET `value` = "%s" WHERE `name` = "messageEditGroupId"', $newGroupId)); if (TableMng::getDb()->affected_rows == 0) { TableMng::query(sprintf('INSERT INTO SystemGlobalSettings (`value`, `name`) VALUES ("%s", "messageEditGroupId")', $newGroupId)); } } catch (Exception $e) { $this->_interface->dieError('Konnte die Gruppe nicht verändern'); } }
/** * Changes a Group based on the given data */ protected function groupsChange() { $query = ''; $changeCounter = 0; if (isset($_POST['data'])) { foreach ($_POST['data'] as &$data) { TableMng::sqlEscape($data); } $query = $this->groupsChangeQuery($_POST['data']); } else { die(json_encode(array('value' => 'error', 'message' => 'No data given!'))); } try { TableMng::getDb()->autocommit(false); TableMng::queryMultiple($query); TableMng::getDb()->autocommit(true); } catch (Exception $e) { die(json_encode(array('value' => 'error', 'message' => 'Konnte die Query nicht ausführen!'))); } die(json_encode(array('value' => 'success', 'message' => 'Die Gruppen wurden erfolgreich geändert!'))); }
private function markMsgAsRead($msgReceiverId) { $db = TableMng::getDb(); $query = sprintf('UPDATE MessageReceivers SET `read` = "1" WHERE ID = "%s";', $db->real_escape_string($msgReceiverId)); if ($db->query($query)) { return; } else { $this->_interface->DieError('Konnte die Nachricht nicht als gelesen markieren' . $db->error); } }
protected function activateSchoolYearInDatabase() { TableMng::getDb()->autocommit(false); TableMng::query("UPDATE SystemSchoolyears SET active = 0\n\t\t\tWHERE active = 1"); TableMng::query("UPDATE SystemSchoolyears SET active = 1\n\t\t\tWHERE ID = {$_GET['ID']}"); TableMng::getDb()->autocommit(true); }