Example #1
0
 function __construct($step_table, $url_is_tab = false)
 {
     global $CFG;
     $this->table = $step_table;
     $this->url_is_tab = $CFG->url == $step_table ? $CFG->is_tab : $url_is_tab;
     if (!DB::tableExists($step_table)) {
         if (DB::createTable($step_table, array('name' => 'vchar', 'group_id' => 'int', 'user_id' => 'int', 'supervisor_id' => 'int', 'days_available' => 'int', 'step_order' => 'int'))) {
             Messages::add($CFG->table_created);
         }
     }
 }
Example #2
0
 function save()
 {
     global $CFG;
     if ($_REQUEST['bypass_save'] || $CFG->save_called || strstr($_REQUEST['form_name'], 'form_filters')) {
         return false;
     }
     $this->save_called = true;
     $CFG->save_called = true;
     if (!$this->get_called && $this->record_id > 0) {
         if (!is_array(self::$old_info_prev)) {
             $this->old_info = DB::getRecord($this->table, $this->record_id, 0, 1);
             self::$old_info_prev = $this->old_info;
         } else {
             $this->old_info = self::$old_info_prev;
         }
         $subtables = DB::getSubtables($this->name);
         if (is_array($subtables)) {
             foreach ($subtables as $subtable) {
                 if (!DB::tableExists($this->table . '_' . $subtable)) {
                     continue;
                 }
                 if (strstr($subtable, 'grid_')) {
                     $name_parts = explode('grid_', $subtable);
                     $name = $name_parts[1];
                     $this->old_info[$name] = DB::getGridValues($this->table . '_grid_' . $name, $subtable_fields, $this->record_id);
                 } elseif (strstr($subtable, 'files')) {
                     //$files = DB::getFiles($this->table.'_files',$this->record_id);
                 } else {
                     if ($this->info['cat_selects'] && $this->info['cat_selects'][$subtable]) {
                         $cats = DB::getCats($this->table . '_' . $subtable, $this->record_id);
                         if ($cats) {
                             foreach ($cats as $cat) {
                                 $this->old_info['cat_selects'][$subtable][] = $cat['row']['c_id'];
                             }
                         }
                     }
                 }
             }
         }
     }
     /*
     		if ($CFG->backstage_mode && !empty($_REQUEST['trigger_field'])) {
     			if (is_array($_REQUEST['trigger_field'])) {
     				foreach ($_REQUEST['trigger_field'] as $k => $tfield) {
     					self::emailNotify($tfield,$_REQUEST['trigger_value'][$k],$_REQUEST['email_field'][$k],$_REQUEST['email_table'][$k],$_REQUEST['email_record'][$k]);
     				}
     				$this->bypass_email = true;
     			}
     		}
     */
     /*
     		if ($CFG->backstage_mode && !empty($_REQUEST['trigger_field1'])) {
     			if (is_array($_REQUEST['trigger_field1'])) {
     				foreach ($_REQUEST['trigger_field1'] as $k => $tfield) {
     					if (!empty($tfield)) {
     						self::createRecord($_REQUEST['create_record_table'][$k],$tfield,$_REQUEST['trigger_value'][$k]);
     					}
     				}
     			}
     		}
     */
     if ($_FILES[$this->name]['name']) {
         foreach ($_FILES[$this->name]['name'] as $input_name => $file_name) {
             if ($file_name) {
                 $temp_files[] = Upload::saveTemp($this->name, $input_name);
             }
         }
         if (is_array($temp_files)) {
             foreach ($temp_files as $file_info) {
                 $field_name = $file_info['input_name'];
                 if ($file_info['error']) {
                     $this->errors[$field_name] = $file_info['error'];
                 } else {
                     $this->temp_files[$field_name] = $file_info['filename'];
                     $CFG->temp_files[$field_name] = $file_info['filename'];
                     $this->temp_descs[$field_name] = $file_info['file_desc'];
                 }
             }
         }
     }
     if ($this->info && !$this->errors) {
         if ($CFG->auto_create_table) {
             if (!DB::tableExists($this->table)) {
                 if (DB::createTable($this->table, $_REQUEST['db_fields'], $_REQUEST['radioinputs'], $this->ignore_fields)) {
                     $this->messages[$this->table] = $CFG->table_created;
                 } else {
                     $this->errors[] = $CFG->table_creation_error;
                 }
             }
         }
         if (!$this->errors) {
             $insert_values = $this->info;
             if (is_array($this->ignore_fields)) {
                 foreach ($this->ignore_fields as $i_name => $i_table) {
                     unset($insert_values[$i_name]);
                 }
             }
             if (is_array($this->includes)) {
                 foreach ($this->includes as $i_table => $i_info) {
                     if (is_array($this->ignore_fields)) {
                         foreach ($this->info as $key => $value) {
                             if (array_key_exists($key, $this->ignore_fields) && $this->ignore_fields[$key] == $i_table) {
                                 $i_values[$key] = $value;
                             }
                         }
                     }
                     if (!$this->record_id) {
                         $include_ids[$i_table] = DB::insert($i_table, $i_values);
                         $this->include_ids = $include_ids;
                     } else {
                         DB::update($i_table, $i_values, $i_info['id']);
                     }
                 }
             }
             if (!$this->record_id) {
                 if ($include_ids) {
                     $t_fields = DB::getTableFields($this->table, 1);
                     if (is_array($t_fields)) {
                         foreach ($include_ids as $i_table => $i_id) {
                             if (!in_array($i_table . '_include_id', $t_fields)) {
                                 db_query('ALTER TABLE ' . $this->table . ' ADD ' . $i_table . '_include_id INT( 10 ) UNSIGNED NOT NULL ');
                             }
                             $insert_values[$i_table . '_include_id'] = $i_id;
                         }
                     }
                 }
                 if ($this->record_id = DB::insert($this->table, $insert_values, false, $this->ignore_fields)) {
                     $this->record_created = true;
                     $CFG->id = $this->record_id;
                     $this->info['id'] = $this->record_id;
                     $this->messages[] = $CFG->form_save_message;
                 } else {
                     $this->errors[] = $CFG->form_save_error;
                 }
             } else {
                 DB::saveImageOrder($_REQUEST['file_order'], $this->table);
                 if (DB::update($this->table, $insert_values, $this->record_id, $this->ignore_fields) != -1) {
                     $this->record_created = false;
                     $this->messages[$this->record_id] = $CFG->form_update_message;
                     if ($this->table == 'admin_users' && $CFG->url != 'users') {
                         User::logOut(1);
                         User::logIn($this->info['user'], $this->info['pass']);
                     }
                 } else {
                     $this->errors[$this->record_id] = $CFG->form_update_error;
                 }
             }
         }
         if (!$this->errors && is_array($this->temp_files)) {
             foreach ($this->temp_files as $field_name => $file_name) {
                 $field_name_parts = explode('__', $field_name);
                 $field_name_n = $field_name_parts[0];
                 $file_reqs = $_REQUEST['files'][$field_name_n];
                 $image_sizes = $file_reqs['image_sizes'] ? $file_reqs['image_sizes'] : $CFG->image_sizes;
                 if (Upload::save($file_name, $field_name_n, $this->table, $this->record_id, $file_reqs['dir'], $image_sizes, $field_name)) {
                     $this->messages[$file_name] = $CFG->file_save_message;
                     unset($this->temp_files[$field_name]);
                     unset($CFG->temp_files[$field_name]);
                 } else {
                     $this->errors[$file_name] = $CFG->file_save_error;
                 }
             }
         }
         if ($_REQUEST['file_descs']) {
             foreach ($_REQUEST['file_descs'] as $i => $desc) {
                 Upload::saveDescriptions($this->table, false, $i);
             }
         }
     }
 }
Example #3
0
                $active = $_REQUEST['active'] == 1 ? 'Y' : 'N';
                foreach ($rows as $id) {
                    if (!DB::update($table, array('is_active' => $active), $id)) {
                        $errors[] = $CFG->ajax_save_error;
                    }
                }
            }
        }
    }
} elseif ($action == 'delete_file') {
    if (!empty($_REQUEST['filename'])) {
        unlink($_REQUEST['filename']);
    }
} elseif ($action == 'check_table') {
    if (!DB::tableExists($_REQUEST['table'])) {
        DB::createTable($_REQUEST['table'], $_REQUEST['db_fields'], $_REQUEST['radioinputs']);
    } else {
        DB::editTable($_REQUEST['table'], $_REQUEST['db_fields'], $_REQUEST['radioinputs']);
    }
} elseif ($_REQUEST['rows'] && !empty($_REQUEST['rows'])) {
    foreach ($_REQUEST['rows'] as $row) {
        if ($row['info']) {
            if ($row['id']) {
                DB::update($row['table'], $row['info'], $row['id']);
            } else {
                DB::insert($row['table'], $row['info']);
            }
        }
    }
} elseif ($_REQUEST['table']) {
    if ($row['id']) {
 /**
  * Create a temporary table mapping each database record to its version on the given date.
  * This is used by the versioning system to return database content on that date.
  * @param string $baseTable The base table.
  * @param string $date The date.  If omitted, then the latest version of each page will be returned.
  * @todo Ensure that this is DB abstracted
  */
 protected static function requireArchiveTempTable($baseTable, $date = null)
 {
     if (!isset(self::$archive_tables[$baseTable])) {
         self::$archive_tables[$baseTable] = DB::createTable("_Archive{$baseTable}", array("ID" => "INT NOT NULL", "Version" => "INT NOT NULL"), null, array('temporary' => true));
     }
     if (!DB::query("SELECT COUNT(*) FROM \"" . self::$archive_tables[$baseTable] . "\"")->value()) {
         if ($date) {
             $SQL_date = Convert::raw2sql($date);
             $dateClause = "WHERE \"LastEdited\" <= '{$SQL_date}'";
         } else {
             $dateClause = "";
         }
         DB::query("INSERT INTO \"" . self::$archive_tables[$baseTable] . "\"\n\t\t\t\tSELECT \"RecordID\", max(\"Version\") FROM \"{$baseTable}_versions\"\n\t\t\t\t{$dateClause}\n\t\t\t\tGROUP BY \"RecordID\"");
     }
     return self::$archive_tables[$baseTable];
 }
 /**
  *	Create a database table to replay the site tree creation, based on the chronological order of the site tree version table.
  */
 protected function setupStructure()
 {
     if (!DB::getConn() instanceof MySQLDatabase) {
         exit('This task currently only supports <strong>MySQL</strong>...');
     }
     $replaceArray = self::$db_columns;
     unset($replaceArray['FullURL']);
     $this->replaceColumnString = implode(',', array_keys($replaceArray));
     $tableList = DB::tableList();
     if (self::$use_temporary_table || !in_array(self::$default_table, $tableList)) {
         $options = self::$use_temporary_table ? array('temporary' => true) : null;
         $this->replayTable = DB::createTable(self::$default_table, self::$db_columns, null, $options);
     } else {
         // Delete all records from the table.
         $query = new SQLQuery('', self::$default_table);
         $query->setDelete(true);
         $query->execute();
     }
 }
Example #6
0
	/**
	 * Create a temporary table mapping each database record to its version on the given date.
	 * This is used by the versioning system to return database content on that date.
	 * @param string $baseTable The base table.
	 * @param string $date The date.  If omitted, then the latest version of each page will be returned.
	 * @todo Ensure that this is DB abstracted
	 */
	protected static function requireArchiveTempTable($baseTable, $date = null) {
		if(!isset(self::$archive_tables[$baseTable])) {
			self::$archive_tables[$baseTable] = DB::createTable("_Archive$baseTable", array(
				"ID" => "INT NOT NULL",
				"Version" => "INT NOT NULL",
			), null, array('temporary' => true));
		}
		
		if(!DB::query("SELECT COUNT(*) FROM \"" . self::$archive_tables[$baseTable] . "\"")->value()) {
			if($date) $dateClause = "WHERE \"LastEdited\" <= '$date'";
			else $dateClause = "";

			DB::query("INSERT INTO \"" . self::$archive_tables[$baseTable] . "\"
				SELECT \"RecordID\", max(\"Version\") FROM \"{$baseTable}_versions\"
				$dateClause
				GROUP BY \"RecordID\"");
		}
		
		return self::$archive_tables[$baseTable];
	}
Example #7
0
 function __construct($class = false, $folder_table = false, $mode = false, $download_encrypted_group = false, $only_admin_can_download = false)
 {
     global $CFG;
     $this->class = $class ? $class : 'file_manager';
     $this->i = $this->i > 0 ? $this->i : 1;
     $this->folder_table = $folder_table;
     $this->mode = $mode ? $mode : 'icons';
     $this->order_by = $_REQUEST['order_by'];
     $this->order_asc = $_REQUEST['order_asc'];
     $this->current_folder_id = $_REQUEST['current_id'] > 0 ? $_REQUEST['current_id'] : '0';
     $this->current_folder_id = !($_REQUEST['current_id'] > 0 || $_REQUEST['current_id'] == '0') && ($_SESSION['current_folder_id' . $CFG->control_pass_id] > 0 || $_SESSION['current_folder_id' . $CFG->control_pass_id] == '0') ? $_SESSION['current_folder_id' . $CFG->control_pass_id] : $this->current_folder_id;
     $this->history = $_REQUEST['history'];
     $this->bypass = $_REQUEST['fm_bypass'];
     $this->n_or_b = $_REQUEST['b_or_n'];
     $this->download_group = $download_encrypted_group;
     $this->only_admin = $only_admin_can_download;
     $_SESSION['current_folder_id' . $CFG->control_pass_id] = $this->current_folder_id;
     if (!DB::tableExists($folder_table)) {
         if (DB::createTable($folder_table, array('name' => 'vchar', 'p_id' => 'int'))) {
             Messages::add($CFG->table_created);
         }
     }
     $form = new Form('form_filters');
     $this->filter_results = $form->info;
     if (!$this->filter_results) {
         if (!array_key_exists('current_id', $_REQUEST)) {
             $this->filter_results = $_SESSION['current_filter_results' . $CFG->control_pass_id];
             unset($_SESSION['current_filter_results' . $CFG->control_pass_id]);
         }
         $_REQUEST['search_fields'] = $_SESSION['search_fields' . $CFG->control_pass_id];
         $_REQUEST['datefields'] = $_SESSION['datefields' . $CFG->control_pass_id];
         $_REQUEST['month_fields'] = $_SESSION['month_fields' . $CFG->control_pass_id];
         $_REQUEST['year_fields'] = $_SESSION['year_fields' . $CFG->control_pass_id];
         $_REQUEST['cat_selects'] = $_SESSION['cat_selects' . $CFG->control_pass_id];
         $_REQUEST['subtables'] = $_SESSION['subtables'];
         $this->filters1 = $_SESSION['filter_properties' . $CFG->control_pass_id];
     } else {
         $this->current_folder_id = '0';
         $this->filter_results['first_letter'] = $_REQUEST['fl'];
         $this->filter_results['first_letter_field'] = $_REQUEST['fl_field'];
         $this->filter_results['first_letter_subtable'] = $_REQUEST['fl_subtable'];
         $_SESSION['current_filter_results' . $CFG->control_pass_id] = $this->filter_results;
         $_SESSION['search_fields' . $CFG->control_pass_id] = $_REQUEST['search_fields'];
         $_SESSION['datefields' . $CFG->control_pass_id] = $_REQUEST['datefields'];
         $_SESSION['month_fields' . $CFG->control_pass_id] = $_REQUEST['month_fields'];
         $_SESSION['year_fields' . $CFG->control_pass_id] = $_REQUEST['year_fields'];
         $_SESSION['cat_selects' . $CFG->control_pass_id] = $_REQUEST['cat_selects'];
         $_SESSION['subtables'] = $_REQUEST['subtables'];
         if (is_array($_REQUEST['filter_properties'])) {
             foreach ($_REQUEST['filter_properties'] as $properties) {
                 $this->filters1[] = unserialize(urldecode($properties));
             }
             $_SESSION['filter_properties' . $CFG->control_pass_id] = $this->filters1;
         }
     }
     if (is_array($this->filter_results)) {
         foreach ($this->filter_results as $key => $row) {
             if (empty($row)) {
                 unset($this->filter_results[$key]);
             }
         }
     }
     if (count($this->filter_results) > 0) {
         $this->mode = 'search';
     }
 }
 /**
  * Create a temporary table mapping each database record to its version on the given date.
  * 
  * This gives us an easy way of querying the future state at the date passed to this function:
  * we simply join SiteTree_versions to the future table, inner joining on RecordID and Version.
  * 
  * @param string $baseTable The base table.
  * @param string $date The date.
  */
 protected static function requireFutureStateTempTable($baseTable, $date = null)
 {
     $tmpID = "_FutureState{$baseTable}_" . str_replace(array(' ', '-', ':'), '', $date);
     if (!isset(self::$temp_tables[$tmpID])) {
         self::$temp_tables[$tmpID] = DB::createTable($tmpID, array("ID" => "INT NOT NULL", "Version" => "INT NOT NULL", "ExpiryDate" => DB::getConn()->SS_Datetime(array())), null, array('temporary' => true));
     }
     if (!DB::query("SELECT COUNT(*) FROM \"" . self::$temp_tables[$tmpID] . "\"")->value()) {
         $SQL_date = Convert::raw2sql($date);
         $tempTable = self::$temp_tables[$tmpID];
         // Insert current live data
         DB::query("INSERT INTO \"{$tempTable}\"\n\t\t\t\tSELECT \"ID\", \"Version\", \"ExpiryDate\" FROM \"{$baseTable}_Live\"");
         // Remove pages that will be included by the embargo line below, so that we can update
         // without duplication
         DB::query("DELETE FROM \"{$tempTable}\" WHERE \"ID\" IN\n\t\t\t\t(SELECT \"PageID\" FROM \"WorkflowRequest\" \n\t\t\t\tWHERE \"Status\" = 'Scheduled' AND \"EmbargoDate\" <= '{$SQL_date}')");
         // Add/update embargoed pages
         DB::query("INSERT INTO \"{$tempTable}\"\n\t\t\t\tSELECT \"WorkflowRequest\".\"PageID\", \"{$baseTable}\".\"Version\", \"{$baseTable}\".\"ExpiryDate\"\n\t\t\t\tFROM \"WorkflowRequest\" \n\t\t\t\tINNER JOIN \"{$baseTable}\" ON \"{$baseTable}\".\"ID\" = \"WorkflowRequest\".\"PageID\"\n\t\t\t\tWHERE \"WorkflowRequest\" .\"Status\" = 'Scheduled' AND \"WorkflowRequest\" .\"EmbargoDate\" <= '{$SQL_date}'");
         // Remove expired pages
         DB::query("DELETE FROM \"{$tempTable}\" WHERE \"ExpiryDate\" IS NOT NULL AND \"ExpiryDate\" <= '{$SQL_date}'");
         // Remove expired subsite pages
         DB::query("DELETE FROM \"{$tempTable}\" WHERE \"ExpiryDate\" IS NOT NULL AND \"ExpiryDate\" <= '{$SQL_date}'");
         // Add/update embargoed Virtual pages - if the VP already exists on the live site
         if ($baseTable == 'SiteTree') {
             // Remove existing items to prevent duplication
             DB::query("DELETE FROM \"{$tempTable}\" WHERE \"ID\" IN (\n\t\t\t\t\tSELECT \"VirtualPage\".\"ID\"\n\t\t\t\t\tFROM \"WorkflowRequest\" \n\t\t\t\t\tINNER JOIN \"VirtualPage\" ON \"VirtualPage\".\"CopyContentFromID\" = \"WorkflowRequest\".\"PageID\"\n\t\t\t\t\tINNER JOIN \"{$baseTable}_Live\" ON \"VirtualPage\".\"ID\" = \"{$baseTable}_Live\".\"ID\"\n\t\t\t\t\tWHERE \"WorkflowRequest\" .\"Status\" = 'Scheduled' AND \"WorkflowRequest\" .\"EmbargoDate\" <= '{$SQL_date}')");
             // Then insert new ones
             DB::query("INSERT INTO \"{$tempTable}\"\n\t\t\t\t\tSELECT \"VirtualPage\".\"ID\", \"{$baseTable}\".\"Version\", \"{$baseTable}\".\"ExpiryDate\"\n\t\t\t\t\tFROM \"WorkflowRequest\" \n\t\t\t\t\tINNER JOIN \"VirtualPage\" ON \"VirtualPage\".\"CopyContentFromID\" = \"WorkflowRequest\".\"PageID\"\n\t\t\t\t\tINNER JOIN \"{$baseTable}\" ON \"{$baseTable}\".\"ID\" = \"VirtualPage\".\"ID\"\n\t\t\t\t\tINNER JOIN \"{$baseTable}_Live\" ON \"{$baseTable}\".\"ID\" = \"{$baseTable}_Live\".\"ID\"\n\t\t\t\t\tWHERE \"WorkflowRequest\" .\"Status\" = 'Scheduled' AND \"WorkflowRequest\" .\"EmbargoDate\" <= '{$SQL_date}'");
         }
     }
     return self::$temp_tables[$tmpID];
 }