Ejemplo n.º 1
0
 function __destruct()
 {
     cLogsDb::$count_glob--;
     parent::__destruct();
     if (cLogsDb::$count_glob == 0 && DB_DEBUG) {
         //cLogs::$aLogsAll[] = array("DB_QUERIES",cLogsDb::$aDbFileLogs);
         cLogsDb::writeLogsToFile();
     }
 }
            $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) {
            $msg = $e->getDbMessageError(__METHOD__ . '(line:' . __LINE__ . ')', $query);
            $aErrors[] = $msg;
            cLogsDb::addFileLog($msg);
        }
    }
}
/// end of POST data sent ///
###########################################################################################
##################################### code to print #######################################
foreach ($aErrors as $error) {
    print "<div class='error'>{$error}</div>";
}
foreach ($aAlerts as $alert) {
    print "<div class='alert'>{$alert}</div>";
}
?>
<h3>Add new capability</h3>
<form action="" name="fc_capabilities" method="post">
Ejemplo n.º 3
0
 /**
  * drop table
  * @param string $tablename - name of table
  */
 public function dropTable($tablename)
 {
     $class = cDb::$logClass;
     $msg = __CLASS__ . ": " . __FUNCTION__;
     if (is_object($this)) {
         $msg = get_class($this) . ": " . $msg;
     }
     try {
         $query = "DROP TABLE {$tablename}";
         if (!mysql_query($query)) {
             throw new cException("Table {$tablename} couldn't be droped!");
         }
         cLogsDb::addFileLog($query);
         if (is_object($this) && is_object($this->logs)) {
             $this->logs->addLog($query, $msg, "_dbLog");
         } else {
             cDb::$logs->addLog($query, $msg, $class);
         }
         return true;
     } catch (cException $e) {
         $query = $e->getDbMessageError(__METHOD__ . '(line:' . __LINE__ . ')', $query);
         cLogsDb::addFileLog($query);
         cDb::$logs->addLog($query, $msg, $class . " _error");
         return false;
     }
 }
Ejemplo n.º 4
0
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);
    }
}
Ejemplo n.º 5
0
 /**
  * Ulozeni noveho odberatele, pokud je uzivatel prihlasen, ulozi ho pod jeho useraccount
  * @return int/false - ID odberatele in DB nebo vrati false, pokud se nezdarila operace
  */
 private function saveOdberatel()
 {
     /// prihlaseny uzivatel ///
     if (!is_null($this->CFG->getUseraccountId())) {
         $this->aOdbToDb[] = array('useracc', $this->CFG->getUseraccountId(), false);
     }
     $this->aOdbToDb[] = array('nazev', $this->aPost['odb_nazev']);
     $this->aOdbToDb[] = array('ulice', $this->aPost['odb_ulice']);
     $this->aOdbToDb[] = array('mesto', $this->aPost['odb_mesto']);
     $this->aOdbToDb[] = array('psc', $this->aPost['odb_psc']);
     if ($this->aPost['odb_ico'] != "") {
         $this->aOdbToDb[] = array('ico', (int) $this->aPost['odb_ico'], false);
     }
     if ($this->aPost['odb_dic'] != "") {
         $this->aOdbToDb[] = array('dic', $this->aPost['odb_dic']);
     }
     if ($this->aPost['odb_email'] != "") {
         $this->aOdbToDb[] = array('email', $this->aPost['odb_email']);
     }
     if ($this->aPost['odb_tel'] != "") {
         $this->aOdbToDb[] = array('tel', $this->aPost['odb_tel']);
     }
     try {
         if (!$this->db->insert('odberatele', $this->aOdbToDb)) {
             throw new cException(getString("Neočekávaná chyba během ukládání odběratele!", 'faktura'));
         }
         //$this->aAlerts[] = getString("Byl přidán nový odběratel.",'faktura');
     } catch (cException $e) {
         $this->aErrors[] = $e->getMessage();
         cLogsDb::addFileLog($e->getDbMessageError(__METHOD__ . '(line:' . __LINE__ . ')'));
         return false;
     }
     return $this->db->getLastId();
 }