function _updateCapabilities() { global $DB; global $_aErrors; global $_aAlerts; $Check = new cCheckForm(); $colsToDb = array(array('capability', false), array('role', false)); $dataToDb = array(); foreach ($_POST as $k => $v) { $_POST[$k] = get_magic_quotes_gpc() ? trim($v) : trim(addslashes($v)); $aDat = explode('_', $k, 3); /// post data with values for core_role_capability /// if ($aDat[0] == "caprole" && count($aDat) == 3) { $Check->check('cap', 'is_numeric($test)', 'The id of capability is in wrong type', $aDat[1]); $Check->check('role', 'is_numeric($test)', 'The id of role is in wrong type', $aDat[2]); $dataToDb[] = array($aDat[1], $aDat[2]); } } //$Logs->addLog($Check->isValid(), 'valid'); try { if (!$Check->isValid()) { foreach ($Check->getErrors() as $k => $error) { $_aErrors[] = implode("(<strong>{$k}</strong>)<br />", $error['msg']) . "(<strong>{$k}</strong>)"; } throw new cException("Form is not valid!"); } /// make backup of original table /// if (!$DB->createCopyOfTable('core_role_capability', 'core_role_capability_back')) { throw new cException("Some error during backup operation of old data!"); } /// empty original table /// if (!$DB->truncateTable('core_role_capability')) { /// drop backup table /// $DB->dropTable('core_role_capability_back'); throw new cException("Some error during insert operation!"); } /// insert new values to original table /// if (!$DB->insertMore('core_role_capability', $colsToDb, $dataToDb)) { /// copy data from backup to original table /// $DB->createCopyOfTable('core_role_capability_bak', 'core_role_capability'); throw new cException("Some error during insert operation!"); } /// empty backup table /// $DB->dropTable('core_role_capability_back'); $_aAlerts[] = "Capabilities were updated."; } catch (cException $e) { $msg = $e->getDbMessageError(__METHOD__ . '(line:' . __LINE__ . ')', $query); $_aErrors[] = $msg; cLogsDb::addFileLog($msg); } }
$Logs = new cLogs("addcapability.php"); $Logs->on(); $aErrors = array(); $aAlerts = array(); global $DB; if (isset($_POST['add_capab'])) { foreach ($_POST as $k => $v) { $_POST[$k] = get_magic_quotes_gpc() ? trim($v) : trim(addslashes($v)); } $Check = new cCheckForm(); $namePat = '/^[a-zA-Z0-9_-]{1,50}$/'; if ($Check->check('name', 'preg_match("' . $namePat . '",$test)', 'The NAME must be without whitespaces and diacritical marks and max. 50 symbols!')) { $Check->check('name', '$test==false', 'This capability already exists!', admin_capabExists($_POST['name'])); } $Check->check('description', 'strlen($test) > 0 && strlen($test) < 266', 'The description of capability is required with max length 255 symbols!'); $Logs->addLog($Check->isValid(), 'add new one valid'); if (!$Check->isValid()) { foreach ($Check->getErrors() as $k => $error) { $aErrors[] = admin_getErrorToPrint($k, $error); } } else { try { $aVals = array(); $aVals[] = array('name', $_POST['name']); $aVals[] = array('description', $_POST['description']); /// insert values /// if (!$DB->insert('core_capabilities', $aVals)) { throw new cException("Some error during insert operation!"); } $aAlerts[] = "New capability waw added."; } catch (cException $e) {
$Check->check('newtemp', '$test==false', 'The name of TEMPLATES already exists!', admin_tempExists($_POST['newtemp'])); } } if ($Check->check('page', 'preg_match("' . $namePat . '",$test)', 'The name of PAGE must be in lowercase letters, starts with a letter and without whitespaces and diacritical marks and max. 50 symbols! (e.g.: newhomepage or new_home-page1')) { $Check->check('page', '$test==false', 'The name of PAGE already exists!', admin_pageExists($_POST['page'])); } $bTitle = false; foreach ($_POST as $k => $v) { if (substr($k, 0, 3) == 'lng') { /// max 100 symbols /// $Check->check('title' . substr($k, 3), 'strlen($test) > 0 && strlen($test) < 101', 'Title of PAGE' . strtoupper(substr($k, 3)) . ' is required with max. 100 symbols!'); $bTitle = true; } } $Check->check('page_title', '$test == true', 'Title of PAGE is required!', $bTitle); $Logs->addLog($Check->isValid(), 'valid'); //$Logs->addLog($Check->getErrors(),'errors'); if (!$Check->isValid()) { foreach ($Check->getErrors() as $k => $error) { $aErrors[] = admin_getErrorToPrint($k, $error); } $result = false; } else { $result = add_insertNewPage(); } if ($result) { $aAlerts[] = "Page was added."; } $Logs->addLog($result, 'new page RESULT'); } $allTemps = admin_getAllTemps();