function __construct()
 {
     global $osC_Language, $osC_MessageStack;
     $this->_page_title = $osC_Language->get('heading_title');
     if (!isset($_GET['action'])) {
         $_GET['action'] = '';
     }
     if (!isset($_GET['page']) || isset($_GET['page']) && !is_numeric($_GET['page'])) {
         $_GET['page'] = 1;
     }
     if (!isset($_GET['fm'])) {
         $_GET['fm'] = '';
     }
     if (!isset($_GET['fu']) || !is_numeric($_GET['fu'])) {
         $_GET['fu'] = '';
     }
     if (!empty($_GET['action'])) {
         switch ($_GET['action']) {
             case 'info':
                 $this->_page_contents = 'info.php';
                 break;
             case 'delete':
                 $this->_page_contents = 'delete.php';
                 if (isset($_POST['subaction']) && $_POST['subaction'] == 'confirm') {
                     if (osC_AdministratorsLog_Admin::delete($_GET['lID'])) {
                         $osC_MessageStack->add($this->_module, $osC_Language->get('ms_success_action_performed'), 'success');
                     } else {
                         $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_action_not_performed'), 'error');
                     }
                     osc_redirect_admin(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page'] . '&fm=' . $_GET['fm'] . '&fu=' . $_GET['fu']));
                 }
                 break;
             case 'batchDelete':
                 if (isset($_POST['batch']) && is_array($_POST['batch']) && !empty($_POST['batch'])) {
                     $this->_page_contents = 'batch_delete.php';
                     if (isset($_POST['subaction']) && $_POST['subaction'] == 'confirm') {
                         $error = false;
                         foreach ($_POST['batch'] as $id) {
                             if (!osC_AdministratorsLog_Admin::delete($id)) {
                                 $error = true;
                                 break;
                             }
                         }
                         if ($error === false) {
                             $osC_MessageStack->add($this->_module, $osC_Language->get('ms_success_action_performed'), 'success');
                         } else {
                             $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_action_not_performed'), 'error');
                         }
                         osc_redirect_admin(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&page=' . $_GET['page'] . '&fm=' . $_GET['fm'] . '&fu=' . $_GET['fu']));
                     }
                 }
                 break;
         }
     }
 }
Example #2
0
 function execute()
 {
     global $osC_Cache;
     if (isset($this->cache_key)) {
         if ($osC_Cache->read($this->cache_key, $this->cache_expire)) {
             $this->cache_data = $osC_Cache->getCache();
             $this->cache_read = true;
         }
     }
     if ($this->cache_read === false) {
         if ($this->db_class->use_foreign_keys == false) {
             $query_action = substr($this->sql_query, 0, strpos($this->sql_query, ' '));
             if ($query_action == 'delete' || $query_action == 'update') {
                 if (empty($this->db_class->fkeys)) {
                     $Qfk = new self($this->db_class);
                     $Qfk->setQuery('select * from :table_fk_relationships');
                     $Qfk->bindTable(':table_fk_relationships', TABLE_FK_RELATIONSHIPS);
                     //              $Qfk->setCache('fk_relationships');
                     $Qfk->execute();
                     while ($Qfk->next()) {
                         $this->db_class->fkeys[$Qfk->value('to_table')][] = array('from_table' => $Qfk->value('from_table'), 'from_field' => $Qfk->value('from_field'), 'to_field' => $Qfk->value('to_field'), 'on_update' => $Qfk->value('on_update'), 'on_delete' => $Qfk->value('on_delete'));
                     }
                     $Qfk->freeResult();
                 }
             }
             if ($query_action == 'delete') {
                 $query_data = split(' ', $this->sql_query, 4);
                 $query_table = substr($query_data[2], strlen(DB_TABLE_PREFIX));
                 if (isset($this->db_class->fkeys[$query_table])) {
                     // check for RESTRICT constraints first
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         if ($fk['on_delete'] == 'restrict') {
                             $child_query = $this->db_class->simpleQuery('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                             while ($child_result = $this->db_class->next($child_query)) {
                                 $Qcheck = new self($this->db_class);
                                 $Qcheck->setQuery('select ' . $fk['from_field'] . ' from ' . DB_TABLE_PREFIX . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $child_result[$fk['to_field']] . '" limit 1');
                                 $Qcheck->execute();
                                 if ($Qcheck->numberOfRows() === 1) {
                                     $this->db_class->setError('RESTRICT constraint condition from table ' . DB_TABLE_PREFIX . $fk['from_table'], null, $this->sql_query);
                                     return false;
                                 }
                             }
                         }
                     }
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         $parent_query = $this->db_class->simpleQuery('select * from ' . $query_data[2] . ' ' . $query_data[3]);
                         while ($parent_result = $this->db_class->next($parent_query)) {
                             if ($fk['on_delete'] == 'cascade') {
                                 $Qdel = new self($this->db_class);
                                 $Qdel->setQuery('delete from :from_table where :from_field = :' . $fk['from_field']);
                                 $Qdel->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                 $Qdel->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qdel->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']]);
                                 if ($this->logging === true) {
                                     if ($this->db_class->logging_transaction === false) {
                                         $this->db_class->logging_transaction = true;
                                     }
                                     $Qdel->setLogging($this->logging_module, $this->logging_module_id);
                                 }
                                 $Qdel->execute();
                             } elseif ($fk['on_delete'] == 'set_null') {
                                 $Qupdate = new self($this->db_class);
                                 $Qupdate->setQuery('update :from_table set :from_field = :' . $fk['from_field'] . ' where :from_field = :' . $fk['from_field']);
                                 $Qupdate->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                 $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qupdate->bindRaw(':' . $fk['from_field'], 'null');
                                 $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                 $Qupdate->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']], false);
                                 if ($this->logging === true) {
                                     if ($this->db_class->logging_transaction === false) {
                                         $this->db_class->logging_transaction = true;
                                     }
                                     $Qupdate->setLogging($this->logging_module, $this->logging_module_id);
                                 }
                                 $Qupdate->execute();
                             }
                         }
                     }
                 }
             } elseif ($query_action == 'update') {
                 $query_data = split(' ', $this->sql_query, 3);
                 $query_table = substr($query_data[1], strlen(DB_TABLE_PREFIX));
                 if (isset($this->db_class->fkeys[$query_table])) {
                     // check for RESTRICT constraints first
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         if ($fk['on_update'] == 'restrict') {
                             $child_query = $this->db_class->simpleQuery('select ' . $fk['to_field'] . ' from ' . $query_data[2] . ' ' . $query_data[3]);
                             while ($child_result = $this->db_class->next($child_query)) {
                                 $Qcheck = new self($this->db_class);
                                 $Qcheck->setQuery('select ' . $fk['from_field'] . ' from ' . DB_TABLE_PREFIX . $fk['from_table'] . ' where ' . $fk['from_field'] . ' = "' . $child_result[$fk['to_field']] . '" limit 1');
                                 $Qcheck->execute();
                                 if ($Qcheck->numberOfRows() === 1) {
                                     $this->db_class->setError('RESTRICT constraint condition from table ' . DB_TABLE_PREFIX . $fk['from_table'], null, $this->sql_query);
                                     return false;
                                 }
                             }
                         }
                     }
                     foreach ($this->db_class->fkeys[$query_table] as $fk) {
                         // check to see if foreign key column value is being changed
                         if (strpos(substr($this->sql_query, strpos($this->sql_query, ' set ') + 4, strpos($this->sql_query, ' where ') - strpos($this->sql_query, ' set ') - 4), ' ' . $fk['to_field'] . ' ') !== false) {
                             $parent_query = $this->db_class->simpleQuery('select * from ' . $query_data[1] . substr($this->sql_query, strrpos($this->sql_query, ' where ')));
                             while ($parent_result = $this->db_class->next($parent_query)) {
                                 if ($fk['on_update'] == 'cascade' || $fk['on_update'] == 'set_null') {
                                     $on_update_value = '';
                                     if ($fk['on_update'] == 'cascade') {
                                         $on_update_value = $this->logging_fields[$fk['to_field']];
                                     }
                                     $Qupdate = new self($this->db_class);
                                     $Qupdate->setQuery('update :from_table set :from_field = :' . $fk['from_field'] . ' where :from_field = :' . $fk['from_field']);
                                     $Qupdate->bindTable(':from_table', DB_TABLE_PREFIX . $fk['from_table']);
                                     $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                     if (empty($on_update_value)) {
                                         $Qupdate->bindRaw(':' . $fk['from_field'], 'null');
                                     } else {
                                         $Qupdate->bindValue(':' . $fk['from_field'], $on_update_value);
                                     }
                                     $Qupdate->bindRaw(':from_field', $fk['from_field'], false);
                                     $Qupdate->bindValue(':' . $fk['from_field'], $parent_result[$fk['to_field']], false);
                                     if ($this->logging === true) {
                                         if ($this->db_class->logging_transaction === false) {
                                             $this->db_class->logging_transaction = true;
                                         }
                                         $Qupdate->setLogging($this->logging_module, $this->logging_module_id);
                                     }
                                     $Qupdate->execute();
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($this->logging === true) {
             $this->logging_action = substr($this->sql_query, 0, strpos($this->sql_query, ' '));
             if ($this->logging_action == 'update') {
                 $db = split(' ', $this->sql_query, 3);
                 $this->logging_database = $db[1];
                 $test = $this->db_class->simpleQuery('select ' . implode(', ', array_keys($this->logging_fields)) . ' from ' . $this->logging_database . substr($this->sql_query, strrpos($this->sql_query, ' where ')));
                 while ($result = $this->db_class->next($test)) {
                     foreach ($this->logging_fields as $key => $value) {
                         if ($result[$key] != $value) {
                             $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $result[$key], 'new' => $value);
                         }
                     }
                 }
             } elseif ($this->logging_action == 'insert') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 foreach ($this->logging_fields as $key => $value) {
                     $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => '', 'new' => $value);
                 }
             } elseif ($this->logging_action == 'delete') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 $del = $this->db_class->simpleQuery('select * from ' . $this->logging_database . ' ' . $db[3]);
                 while ($result = $this->db_class->next($del)) {
                     foreach ($result as $key => $value) {
                         $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $value, 'new' => '');
                     }
                 }
             }
         }
         $this->query_handler = $this->db_class->simpleQuery($this->sql_query, $this->debug);
         if ($this->logging === true) {
             if ($this->db_class->logging_transaction_action === false) {
                 $this->db_class->logging_transaction_action = $this->logging_action;
             }
             if ($this->affectedRows($this->query_handler) > 0) {
                 if (!empty($this->logging_changed)) {
                     if ($this->logging_action == 'insert' && !is_numeric($this->logging_module_id)) {
                         $this->logging_module_id = $this->db_class->nextID();
                         $this->setNextID($this->logging_module_id);
                     }
                     if (class_exists('osC_AdministratorsLog_Admin')) {
                         osC_AdministratorsLog_Admin::insert($this->logging_module, $this->db_class->logging_transaction_action, $this->logging_module_id, $this->logging_action, $this->logging_changed, $this->db_class->logging_transaction);
                     }
                 }
             }
         }
         if ($this->batch_query === true) {
             $this->batch_size = $this->db_class->getBatchSize($this->sql_query, $this->batch_select_field);
             $this->batch_to = $this->batch_rows * $this->batch_number;
             if ($this->batch_to > $this->batch_size) {
                 $this->batch_to = $this->batch_size;
             }
             $this->batch_from = $this->batch_rows * ($this->batch_number - 1);
             if ($this->batch_to == 0) {
                 $this->batch_from = 0;
             } else {
                 $this->batch_from++;
             }
         }
         return $this->query_handler;
     }
 }
Example #3
0
 function execute()
 {
     global $osC_Cache;
     if (isset($this->cache_key)) {
         if ($osC_Cache->read($this->cache_key, $this->cache_expire)) {
             $this->cache_data = $osC_Cache->getCache();
             $this->cache_read = true;
         }
     }
     if ($this->cache_read === false) {
         if ($this->logging === true) {
             $this->logging_action = substr($this->sql_query, 0, strpos($this->sql_query, ' '));
             if ($this->logging_action == 'update') {
                 $db = split(' ', $this->sql_query, 3);
                 $this->logging_database = $db[1];
                 $test = $this->db_class->simpleQuery('select ' . implode(', ', array_keys($this->logging_fields)) . ' from ' . $this->logging_database . substr($this->sql_query, osc_strrpos_string($this->sql_query, ' where ')));
                 while ($result = $this->db_class->next($test)) {
                     foreach ($this->logging_fields as $key => $value) {
                         if ($result[$key] != $value) {
                             $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $result[$key], 'new' => $value);
                         }
                     }
                 }
             } elseif ($this->logging_action == 'insert') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 foreach ($this->logging_fields as $key => $value) {
                     $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => '', 'new' => $value);
                 }
             } elseif ($this->logging_action == 'delete') {
                 $db = split(' ', $this->sql_query, 4);
                 $this->logging_database = $db[2];
                 $del = $this->db_class->simpleQuery('select * from ' . $this->logging_database . ' ' . $db[3]);
                 while ($result = $this->db_class->next($del)) {
                     foreach ($result as $key => $value) {
                         $this->logging_changed[] = array('key' => $this->logging_database . '.' . $key, 'old' => $value, 'new' => '');
                     }
                 }
             }
         }
         $this->query_handler = $this->db_class->simpleQuery($this->sql_query, $this->debug);
         if ($this->logging === true) {
             if ($this->db_class->logging_transaction_action === false) {
                 $this->db_class->logging_transaction_action = $this->logging_action;
             }
             if ($this->affectedRows($this->query_handler) > 0) {
                 if (!empty($this->logging_changed)) {
                     if ($this->logging_action == 'insert' && !is_numeric($this->logging_module_id)) {
                         $this->logging_module_id = $this->db_class->nextID();
                         $this->setNextID($this->logging_module_id);
                     }
                     if (class_exists('osC_AdministratorsLog_Admin')) {
                         osC_AdministratorsLog_Admin::insert($this->logging_module, $this->db_class->logging_transaction_action, $this->logging_module_id, $this->logging_action, $this->logging_changed, $this->db_class->logging_transaction);
                     }
                 }
             }
         }
         if ($this->batch_query === true) {
             $this->batch_size = $this->db_class->getBatchSize($this->sql_query, $this->batch_select_field);
             $this->batch_to = $this->batch_rows * $this->batch_number;
             if ($this->batch_to > $this->batch_size) {
                 $this->batch_to = $this->batch_size;
             }
             $this->batch_from = $this->batch_rows * ($this->batch_number - 1);
             if ($this->batch_to == 0) {
                 $this->batch_from = 0;
             } else {
                 $this->batch_from++;
             }
         }
         return $this->query_handler;
     }
 }
Example #4
0
<?php

/*
  $Id: $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2009 osCommerce

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License v2 (1991)
  as published by the Free Software Foundation.
*/
$osC_ObjectInfo = new osC_ObjectInfo(osC_AdministratorsLog_Admin::getData($_GET['lID']));
?>

<h1><?php 
echo osc_link_object(osc_href_link_admin(FILENAME_DEFAULT, $osC_Template->getModule()), $osC_Template->getPageTitle());
?>
</h1>

<?php 
if ($osC_MessageStack->size($osC_Template->getModule()) > 0) {
    echo $osC_MessageStack->get($osC_Template->getModule());
}
?>

<div class="infoBoxHeading"><?php 
echo osc_icon('trash.png') . ' ' . $osC_ObjectInfo->get('user_name') . ' &raquo; ' . $osC_ObjectInfo->get('module_action') . ' &raquo; ' . $osC_ObjectInfo->get('module') . ' &raquo; ' . $osC_ObjectInfo->get('module_id');
?>