Exemplo n.º 1
0
function databaseToExcel($tableName, $firmId, $examId, $dir)
{
    $filename = "sinav_" . $firmId . "_" . $examId . ".xls";
    $db =& JFactory::getDBO();
    $query = "SELECT * FROM " . $tableName . " WHERE firmaId = " . $firmId . " AND sinavId = " . $examId;
    $db->setQuery($query);
    $data = $db->loadRowList();
    $tableFields = getTableFields($tableName);
    $columnNumber = getNumColumns($tableName);
    $phpExcel = new PHPExcel();
    //Configure the sheet
    $sheet = $phpExcel->getActiveSheet();
    $sheet->setTitle("jos_deneme");
    //Header
    for ($i = 3; $i < $columnNumber; $i++) {
        $value = $tableFields[$i];
        $sheet->setCellValueByColumnAndRow($i - 3, 1, $value);
    }
    //Data
    $row = 2;
    foreach ($data as $rows) {
        $column = 0;
        for ($i = 3; $i < $columnNumber; $i++) {
            $sheet->setCellValueByColumnAndRow($column, $row, $rows[$i]);
            $column++;
        }
        $row++;
    }
    $writer = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel5');
    $writer->save($dir . $filename);
    $redirect = JURI::base() . $dir . $filename;
    header('Location: ' . $redirect);
}
Exemplo n.º 2
0
Arquivo: act.php Projeto: hunglmtb/eb
<?php

require_once '../lib/db.php';
require_once '../lib/utils.php';
$act = $_REQUEST[act];
if ($act == 'getTableFields') {
    $table = $_REQUEST[table];
    $field = $_REQUEST[field];
    echo getTableFields($table, "decimal,int,double", $field, false);
    exit;
} else {
    if ($act == 'getTableFieldsAll') {
        $table = $_REQUEST[table];
        $field = $_REQUEST[field];
        echo getTableFields($table, "", $field, false);
        exit;
    } else {
        if ($act == 'deleterows') {
            $table = $_REQUEST["table"];
            $id = $_REQUEST["id"];
            $sql = "delete from {$table} where id in ({$id})";
            $result = mysql_query($sql) or die(mysql_error());
            exit;
        }
    }
}
Exemplo n.º 3
0
/**
 * Правильная функция isFieldExists
 * сделана для случая, если сначала выполнится инсталлер, а потом заменятся файлы
 */
function isFieldExists($table_name, $field)
{
    $table_fields = getTableFields($table_name);
    return in_array($field, $table_fields, true);
}
function copySettings($table, $game1, $game2)
{
    global $db;
    $db->query("SELECT game FROM {$table} WHERE game='{$game2}' LIMIT 1;");
    if ($db->num_rows() != 0) {
        $ret = 'Target gametype exists, nothing done!';
    } else {
        $db->query("SELECT count(game) AS cnt FROM {$table} WHERE game='{$game1}';");
        $r = $db->fetch_array();
        if ($r['cnt'] == 0) {
            $ret = 'No data existent for source gametype.';
        } else {
            $ret = $r['cnt'] . ' entries copied!';
            $fields = '';
            $ignoreFields = array('game', 'id', 'd_winner_id', 'd_winner_count', 'g_winner_id', 'g_winner_count', 'count', 'picked', 'kills', 'deaths', 'headshots');
            foreach (getTableFields($table, 0) as $field) {
                if (!in_array($field, $ignoreFields)) {
                    if ($fields != '') {
                        $fields .= ', ';
                    }
                    $fields .= $field;
                }
            }
            $SQL = "INSERT INTO {$table} ({$fields},game) SELECT {$fields},'{$game2}' FROM {$table} WHERE game='{$game1}';";
            $db->query($SQL);
        }
    }
    return $ret . "</li>";
}
Exemplo n.º 5
0
 /**
  * Add or edit a row in violator_notifications table via AJAX
  *
  * @param int $merchant_name_id
  */
 function violator_notification($merchant_name_id)
 {
     $this->_response_type('json');
     $this->data->status = FALSE;
     $this->data->html = '';
     $cmn = $this->crawl_data->crowlMerchantByID($merchant_name_id);
     $type = 'known_seller';
     if (!empty($cmn->marketplace)) {
         if (!$this->Marketplace->is_retailer($cmn->marketplace)) {
             $type = 'unknown_seller';
         }
     }
     $data = array('id' => NULL, 'store_id' => $this->store_id, 'crowl_merchant_name_id' => (int) $merchant_name_id, 'notification_type' => $type);
     $fields = getTableFields($this->_table_violator_notifications, array_keys($data));
     unset($data['id']);
     $data = array_merge($data, $this->input->post_default($fields, NULL, TRUE));
     $data['active'] = empty($data['active']) ? 0 : 1;
     $edit_row = $this->store_m->get_violator_notification_by_seller($merchant_name_id, $data['store_id']);
     $crowl_merchant = $this->crawl_data->crowlMerchantByID($merchant_name_id);
     // Validate the request data
     $errors = array();
     if (!$crowl_merchant) {
         $errors[] = 'An error occurred and the seller was not found.';
     }
     if (!valid_email($data['email_to'])) {
         $errors[] = 'Please provide a valid email address to notify.';
     }
     if (!valid_email($data['email_from'])) {
         $errors[] = 'Please provide a valid reply email address.';
     }
     if (!empty($errors)) {
         $this->data->html = '<p>' . implode('</p><p>', $errors) . '</p>';
         ajax_return($this->data);
     }
     // Everything is valid, let's add the notification
     if (!empty($edit_row) && !$edit_row['default']) {
         if ($this->store_m->update_violator_notification($edit_row['id'], $data)) {
             $this->data->status = TRUE;
             $this->data->html = 'The violation notification has been updated.';
         } else {
             $this->data->html = 'The notification could not be updated.';
         }
     } else {
         if ($this->store_m->create_violator_notification($data)) {
             $this->data->status = TRUE;
             $this->data->html = 'The violation notification has been created.';
         } else {
             $this->data->html = 'The notification could not be created.';
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Handle the AJAX request to update or remove SMTP settings
  */
 public function update_smtp($remove = FALSE)
 {
     $this->_response_type('json');
     // If the update is to remove the record that is all we need to do
     if ($remove) {
         if ($this->data->status = $this->data->remove = $this->_remove_smtp()) {
             $this->data->html = 'Your SMTP settings have been removed.';
         } else {
             $this->data->html = 'Your SMTP settings could not be removed.';
         }
         return;
     }
     // Otherwise, update the record
     $fields = getTableFields($this->_table_store_smtp, array('id', 'store_id'));
     $data = $this->input->post($fields);
     $data['password'] = $this->input->post_orig('password', FALSE);
     // get this value unfiltered
     $data['store_id'] = $this->store_id;
     // validate the data
     $errors = array();
     if (!$this->_validate_smtp($data['host'], $data['port'], $data['use_ssl'], $data['use_tls'])) {
         $errors[] = $data['host'] . ':' . $data['port'] . ' is not a valid URL. Please check that the host and port are correct.';
     }
     if (!empty($errors)) {
         $this->data->html = '<p>' . implode('</p><p>', $errors) . '</p>';
         return;
     }
     // Check if the password contains our mask
     // If it doesn't, then it has been updated
     $fake_password_mask = str_repeat('*', 512);
     if (strpos($data['password'], $fake_password_mask) !== FALSE) {
         unset($data['password']);
     }
     // add to database
     $this->data->status = $this->Store->set_store_smtp($data['store_id'], $data);
     if ($this->data->status) {
         $this->data->html = 'Your SMTP settings have been updated.';
     } else {
         $this->data->html = 'Your SMTP settings could not be updated.';
     }
 }
Exemplo n.º 7
0
$re = mysql_query($s) or die("fail: " . $s . "- error:" . mysql_error());
while ($row = mysql_fetch_array($result)) {
    $i++;
    $ids .= "{$row['ID']};";
    if ($i % 2 == 0) {
        $bgcolor = "#eeeeee";
    } else {
        $bgcolor = "#f8f8f8";
    }
    $x_system = str_replace("value='{$row['SYSTEM_ID']}'", "value='{$row['SYSTEM_ID']}' selected", $c_system);
    $x_freq = str_replace("value='{$row['FREQUENCY']}'", "value='{$row['FREQUENCY']}' selected", $c_freq);
    $x_override = str_replace("value='{$row['ALLOW_OVERRIDE']}'", "value='{$row['ALLOW_OVERRIDE']}' selected", $c_override);
    $x_table = str_replace("value='{$row['TABLE_NAME']}'", "value='{$row['TABLE_NAME']}' selected", $c_table);
    $x_object = str_replace("value='{$row['OBJECT_ID']}'", "value='{$row['OBJECT_ID']}' selected", $c_object);
    //$x_column=loadCodes("INT_TABLE_COLUMN",false,"TABLE_NAME",$row[TABLE_NAME],$row[COLUMN_NAME],"","COLUMN_NAME","COLUMN_NAME");
    $x_column = getTableFields($row[TABLE_NAME], "decimal", $row[COLUMN_NAME], false);
    if (!$x_column) {
        $x_column = "<option value='{$row['COLUMN_NAME']}'>{$row['COLUMN_NAME']}</option>";
    }
    $x_eventtype = str_replace("value='{$row['EVENT_TYPE']}'", "value='{$row['EVENT_TYPE']}' selected", $c_eventtype);
    $x_flowphase = str_replace("value='{$row['FLOW_PHASE']}'", "value='{$row['FLOW_PHASE']}' selected", $c_flowphase);
    $tablename = $row[TABLE_NAME];
    echo "<tr id='oldRow{$row['ID']}' bgcolor='{$bgcolor}' height='26'>";
    mysql_data_seek($re, 0);
    while ($ro = mysql_fetch_array($re)) {
        $f = $ro[COLUMN_NAME];
        if ($f == 'SYSTEM_ID') {
            echo "<td><select size='1' style='width:100%' name='SYSTEM_ID" . $row[ID] . "'>" . $x_system . "</select></td>";
        } else {
            if ($f == 'FREQUENCY') {
                echo "<td><select size='1' style='width:100%' name='FREQUENCY" . $row[ID] . "'>" . $x_freq . "</select></td>";
Exemplo n.º 8
0
 /**
  * Add a violator_notifications_history row using the
  * violator_notification data
  *
  * @param int $id
  * @return int/FALSE
  */
 public function record_violator_notification($id, $email_level, $regarding = NULL)
 {
     $vn = $this->get_violator_notification_by_id($id);
     if (!$vn) {
         return FALSE;
     }
     $fields = getTableFields($this->_table_violator_notifications_history, array('id'));
     $data = array();
     foreach ($fields as $field) {
         if (isset($vn[$field])) {
             $data[$field] = $vn[$field];
         }
     }
     $data['email_level'] = (int) $email_level;
     $data['regarding'] = $regarding;
     $data['date'] = date('Y-m-d H:i:s');
     return $this->create_violator_notifications_history($data);
 }
Exemplo n.º 9
0
$user = console::read('User (default: root):>');
$pass = console::read('Pass (default: null):>');
$dbname = console::read('DB Name (default: test):>');
$folder = empty($folder) ? '/models' : $folder;
$host = empty($host) ? 'localhost' : $host;
$user = empty($user) ? 'root' : $user;
$pass = empty($pass) ? '' : $pass;
$dbname = empty($dbname) ? 'test' : $dbname;
DB::init($host, $user, $pass, $dbname);
$model_location = __DIR__ . '/../..' . $folder . '/';
$models = getTables();
foreach ($models as $newModel) {
    $file = $newModel . '.php';
    if (!file_exists($model_location . $file)) {
        console::write('[+] Model ' . $newModel . ': ', false);
        $data = getTableFields($newModel);
        $fields = $data['fields'];
        $pks = $data['pk'];
        $modelBody = '<?php' . PHP_EOL . PHP_EOL;
        $modelBody .= '// model autogenerated by model_maker.php' . PHP_EOL;
        $modelBody .= 'class ' . $newModel . ' extends table' . PHP_EOL;
        $modelBody .= '{' . PHP_EOL;
        $modelBody .= '    // Primary keys' . PHP_EOL;
        console::write('[pks: ' . count($pks) . '] - ', false);
        if (count($pks) == 1) {
            $modelBody .= '    protected $primaryKeys = \'' . $pks[0] . '\';' . PHP_EOL . PHP_EOL;
        } else {
            $pks = implode('\', \'', $pks);
            $modelBody .= '    protected $primaryKeys = array(\'' . $pks . '\');' . PHP_EOL . PHP_EOL;
        }
        $modelBody .= '    // fields:' . PHP_EOL;
Exemplo n.º 10
0
 function getNewsHeadlines($intLimit = 7, $isPaged = false)
 {
     global $sqli;
     $arrData = array();
     $arrFields = getTableFields(NEWS_TABLE);
     $intLimit = $sqli->real_escape_string($intLimit);
     if ($isPaged === true) {
         $strLimit = $intLimit;
     } else {
         $strLimit = "LIMIT {$intLimit}";
     }
     $sql = "SELECT " . implode(',', $arrFields) . " FROM `" . NEWS_TABLE . "` WHERE `status`=1 ORDER BY CONCAT(`news_post_month`,`news_post_day`,`news_post_year`) DESC {$strLimit};";
     $res = $sqli->query($sql) or die($sqli->error);
     while ($row = $res->fetch_assoc()) {
         $arrTemp = array();
         foreach ($arrFields as $key => $val) {
             $arrTemp[$val] = $row[$val];
         }
         $arrData[$row['id']] = $arrTemp;
     }
     closeMeUp($res);
     return $arrData;
 }