コード例 #1
0
 public static function addWhereConditionToUserConstraints($constraints)
 {
     $where = array();
     if (isset($constraints['archive'])) {
         $constraints['archive'] ? $where[] = 'u.archive!=0' : ($where[] = 'u.archive=0');
     }
     if (isset($constraints['active'])) {
         $constraints['active'] ? $where[] = 'u.active=1' : ($where[] = 'u.active=0');
     }
     if (isset($constraints['filter']) && $constraints['filter']) {
         $result = eF_describeTable("users");
         $tableFields = array();
         foreach ($result as $value) {
             if ($value['Field'] != 'password' && $value['Field'] != 'timestamp') {
                 $tableFields[] = "u." . $value['Field'] . ' like "%' . $constraints['filter'] . '%"';
             }
         }
         $where[] = "(" . implode(" OR ", $tableFields) . ")";
     }
     if (isset($constraints['condition'])) {
         $where[] = $constraints['condition'];
     }
     if (G_VERSIONTYPE == 'enterprise') {
         #cpp#ifdef ENTERPRISE
         if (isset($constraints['branch']) && is_numeric($constraints['branch'])) {
             $where[] = "module_hcd_employee_works_at_branch.branch_ID = '" . $constraints['branch'] . "' AND module_hcd_employee_works_at_branch.assigned = 1";
         } else {
             if (isset($constraints['branch']) && is_array($constraints['branch']) && !empty($constraints['branch'])) {
                 $where[] = "module_hcd_employee_works_at_branch.branch_ID in ('" . implode("','", $constraints['branch']) . "') AND module_hcd_employee_works_at_branch.assigned = 1";
             }
         }
         if (isset($constraints['jobs']) && $constraints['jobs'] != _ALLJOBS && $constraints['jobs'] != '') {
             $where[] = "module_hcd_job_description.description = '" . $constraints['jobs'] . "'";
         }
     }
     #cpp#endif
     if (isset($constraints['table_filters'])) {
         foreach ($constraints['table_filters'] as $constraint) {
             $where[] = $constraint['condition'];
         }
     }
     return $where;
 }
コード例 #2
0
ファイル: system.class.php プロジェクト: bqq1986/efront
 /**
  * Restore system
  *
  * This function is used to restore a backup previously taken
  * <br/>Example:
  * <code>
  * </code>
  *
  * @param EfrontFile $restoreFile The file restore from
  * @param boolean $force Force restore even if versions are incompatible
  * @since 3.5.2
  * @access public
  */
 public static function restore($restoreFile, $force = false)
 {
     if (!$restoreFile instanceof EfrontFile) {
         $restoreFile = new EfrontFile($restoreFile);
     }
     $tempDir = G_BACKUPPATH . 'temp/';
     if (is_dir($tempDir)) {
         $dir = new EfrontDirectory($tempDir);
         $dir->delete();
     }
     mkdir($tempDir, 0755);
     $restoreFile = $restoreFile->copy($tempDir . '/');
     $restoreFile->uncompress(false);
     $filesystem = new FileSystemTree($tempDir);
     $iterator = new EfrontFileOnlyFilterIterator(new RecursiveIteratorIterator($filesystem->tree, RecursiveIteratorIterator::SELF_FIRST));
     foreach ($iterator as $key => $value) {
         if (strpos($key, 'version.txt') !== false) {
             $backupVersion = file_get_contents($key);
         }
     }
     if (version_compare($backupVersion, G_VERSION_NUM) != 0 && !$force) {
         throw new Exception(_INCOMPATIBLEVERSIONS . '<br/> ' . _BACKUPVERSION . ':' . $backupVersion . ' / ' . _CURRENTVERSION . ': ' . G_VERSION_NUM, EfrontSystemException::INCOMPATIBLE_VERSIONS);
     }
     $sql = file_get_contents($tempDir . 'db_backup/sql.txt');
     $sql = explode(";\n", $sql);
     $node = $filesystem->seekNode($tempDir . 'db_backup');
     for ($i = 0; $i < sizeof($sql); $i += 2) {
         preg_match("/drop table (.+)/", $sql[$i], $matches);
         if ($matches[1]) {
             $temp[$matches[1]] = array($sql[$i], $sql[$i + 1]);
         }
     }
     $sql = $temp;
     //For each one of the tables that have backup data, recreate its table and import data
     $iterator = new EfrontFileOnlyFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($node), RecursiveIteratorIterator::SELF_FIRST));
     $GLOBALS['db']->Execute("SET FOREIGN_KEY_CHECKS=0");
     foreach ($iterator as $file => $value) {
         $tableName = preg_replace("/\\.\\d+/", "", basename($file));
         if (isset($sql[$tableName])) {
             try {
                 eF_executeNew($sql[$tableName][0]);
             } catch (Exception $e) {
                 /*Don't halt for missing tables that can't be deleted*/
             }
             eF_executeNew($sql[$tableName][1]);
             unset($sql[$tableName]);
         }
         if (strpos($file, 'sql.txt') === false && strpos($file, 'version.txt') === false) {
             $data = unserialize(file_get_contents($file));
             $tableExists = false;
             try {
                 $tableExists = eF_describeTable($tableName);
             } catch (Exception $e) {
             }
             if ($tableExists !== false && !preg_match("/^\\w+_view\$/", $tableName)) {
                 eF_insertTableDataMultiple($tableName, $data);
             }
         }
     }
     $GLOBALS['db']->Execute("SET FOREIGN_KEY_CHECKS=1");
     //Turn off foreign key checks in order to be able to run "drop table" queries
     eF_executeNew("SET FOREIGN_KEY_CHECKS = 0;");
     //For each one of the tables that don't have backup data, simply recreate
     foreach ($sql as $tableName => $query) {
         try {
             eF_executeNew($query[0]);
         } catch (Exception $e) {
             /*Don't halt for missing tables that can't be deleted*/
         }
         eF_executeNew($query[1]);
     }
     eF_executeNew("SET FOREIGN_KEY_CHECKS = 1;");
     if (is_dir(G_BACKUPPATH . 'temp/upload')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/upload');
         $dir->copy(G_ROOTPATH . 'upload', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/lessons')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/lessons');
         $dir->copy(G_CONTENTPATH . 'lessons', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/efront_root')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/efront_root');
         $dir->copy(G_ROOTPATH, true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/certificate_templates')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/certificate_templates');
         $dir->copy(G_ROOTPATH . 'www/certificate_templates', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/editor_templates')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/editor_templates');
         $dir->copy(G_ROOTPATH . 'www/content/editor_templates', true);
     }
     $dir = new EfrontDirectory($tempDir);
     $dir->delete();
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     }
     return true;
 }
コード例 #3
0
 private static function addWhereConditionToCourseConstraints($constraints)
 {
     $where = array();
     if (isset($constraints['archive'])) {
         $constraints['archive'] ? $where[] = 'c.archive!=0' : ($where[] = 'c.archive=0');
     }
     if (isset($constraints['active'])) {
         $constraints['active'] ? $where[] = 'c.active=1' : ($where[] = 'c.active=0');
     }
     if (isset($constraints['instance'])) {
         if ($constraints['instance'] === true) {
             $where[] = 'c.instance_source!=0';
         } else {
             if ($constraints['instance'] == false) {
                 $where[] = 'c.instance_source=0';
             } else {
                 if (eF_checkParameter($constraints['instance'], 'id')) {
                     $where[] = '(c.instance_source=' . $constraints['instance'] . ' or c.id=' . $constraints['instance'] . ')';
                 }
             }
         }
     }
     if (isset($constraints['filter']) && eF_checkParameter($constraints['filter'], 'text')) {
         $constraints['filter'] = trim(urldecode($constraints['filter']), "||||");
         $result = eF_describeTable("courses");
         $tableFields = array();
         foreach ($result as $value) {
             $tableFields[] = "c." . $value['Field'] . ' like "%' . $constraints['filter'] . '%"';
         }
         $where[] = "(" . implode(" OR ", $tableFields) . ")";
     }
     if (isset($constraints['condition'])) {
         $where[] = $constraints['condition'];
     }
     if (isset($constraints['table_filters'])) {
         foreach ($constraints['table_filters'] as $constraint) {
             $where[] = $constraint['condition'];
         }
     }
     if (isset($constraints['branch_url']) && defined('G_BRANCH_URL') && G_BRANCH_URL) {
         $tree = new EfrontBranchesTree();
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($tree->getNodeChildren($_SESSION['s_current_branch'])), RecursiveIteratorIterator::SELF_FIRST));
         $subbranches[] = $_SESSION['s_current_branch'];
         foreach ($iterator as $key => $value) {
             $subbranches[] = $key;
         }
         $where[] = 'cb.branches_ID in (' . implode(',', $subbranches) . ')';
     }
     return $where;
 }
コード例 #4
0
 private static function addWhereConditionToLessonConstraints($constraints)
 {
     $where = array();
     if (isset($constraints['archive'])) {
         $constraints['archive'] ? $where[] = 'l.archive!=0' : ($where[] = 'l.archive=0');
     }
     if (isset($constraints['active'])) {
         $constraints['active'] ? $where[] = 'l.active=1' : ($where[] = 'l.active=0');
     }
     if (isset($constraints['filter']) && eF_checkParameter($constraints['filter'], 'text')) {
         $constraints['filter'] = trim(urldecode($constraints['filter']), "||||");
         $result = eF_describeTable("lessons");
         $tableFields = array();
         foreach ($result as $value) {
             $tableFields[] = "l." . $value['Field'] . ' like "%' . $constraints['filter'] . '%"';
         }
         $where[] = "(" . implode(" OR ", $tableFields) . ")";
     }
     if (isset($constraints['condition'])) {
         $where[] = $constraints['condition'];
     }
     if (isset($constraints['table_filters'])) {
         foreach ($constraints['table_filters'] as $constraint) {
             $where[] = $constraint['condition'];
         }
     }
     return $where;
 }