Beispiel #1
0
         }
     }
 }
 switch ($action) {
     case 'alm_tables':
         $alm_sqlcmd = file_get_contents(ALMIDONDIR . '/sql/alm.tables.sql');
         # Remove OWNER TO, since only postgres can do so
         $alm_sqlcmd = preg_replace('/^(.*)OWNER TO(.*);$/m', '', $alm_sqlcmd);
         $data = new Data();
         list($type, $tmp) = preg_split('/:\\/\\//', $admin_dsn);
         if ($type == 'pgsql') {
             $sqlcmd = "SELECT relname FROM pg_class WHERE  pg_class.relkind = 'r' AND pg_class.relname LIKE 'alm_%'";
         } elseif ($type == 'mysql') {
             $sqlcmd = "SHOW TABLES LIKE 'alm_%'";
         }
         $var = $data->getList($sqlcmd);
         if (count($var) >= 5) {
             $output .= '<br/>Tablas de almidon ya existen. Re-generando solo meta-datos.<br/>';
             $data->execSql("DELETE FROM alm_access");
             $data->execSql("DELETE FROM alm_column");
             $data->execSql("DELETE FROM alm_table");
         } else {
             $data->execSql($alm_sqlcmd);
             $output = "BD Almidonizada!<br/>Codigo SQL aplicado:<br/><pre>{$alm_sqlcmd}</pre><br/>";
         }
         $alm_table = new alm_tableTable();
         $alm_column = new alm_columnTable();
         # Nota: no hay soporte para TableDoubleKey yet...
         $rank = 1;
         $output .= "Re-generando: ";
         foreach ($tables as $key) {
 public function data()
 {
     // Extractaire des data dans la base
     $datas = Data::getList('SELECT * FROM data ORDER BY date ASC');
     // Extractaire des students avec le tmp_id
     global $students;
     $students = Student::getList('SELECT id, tmp_id FROM student ORDER BY id ASC');
     function getRealStudentId($tmp_id)
     {
         global $students;
         //echo '<pre>'.print_r($students,true).'</pre>';
         foreach ($students as $student) {
             if ($student->tmp_id == $tmp_id) {
                 return $student->id;
             }
         }
         return 0;
     }
     //echo getRealStudentId(11);
     //exit;
     // Enlever la première ligne et formater les dates
     $data_bis = [];
     $date_sort = [];
     $presences = [];
     foreach ($datas as $index => $data) {
         if ($index == 0) {
             continue;
         }
         $data_row = [];
         $presences_row = [];
         $idx = 0;
         foreach ($data->getFields() as $key => $item) {
             $presences_row['student_id'] = null;
             if ($key == 'date') {
                 $arr = explode('/', $data->{$key});
                 $date = $arr[2] . '-' . sprintf('%02d', $arr[0]) . '-' . sprintf('%02d', $arr[1]);
                 $data_row[] = $date;
                 $date_sort[$index] = $date;
                 $presences_row['day'] = $date;
             } else {
                 $value = $data->{$key};
                 $data_row[] = $value;
                 $presences_row['student_id'] = getRealStudentId($idx);
                 //echo $idx.' '.getRealStudentId($idx);
                 $presences_row['r1'] = strpos($value, 'R1') === false ? null : 1;
                 $presences_row['r2'] = strpos($value, 'R2') === false ? null : 1;
                 $presences_row['d1'] = strpos($value, 'D1') === false ? null : 1;
                 $presences_row['d2'] = strpos($value, 'D2') === false ? null : 1;
                 $presences_row['absent'] = $value == 0 ? 1 : 0;
             }
             //echo '<pre>'.print_r($presences_row,true).'</pre>';
             //exit;
             $presences[] = $presences_row;
             $idx++;
         }
         //if ($index==1) echo '<br>';
         $data_bis[] = $data_row;
     }
     // Trier sur les dates
     array_multisort($date_sort, SORT_ASC, SORT_STRING, $data_bis);
     // Afficher la view
     $vars = ['datas' => $datas, 'presences' => $presences];
     $this->render('admin/data', $vars);
 }
Beispiel #3
0
 /**
  * Parse date and split in named array fields
  *
  * @param   string  $date     Date string to parse
  * @param   array   $options  Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details.
  * @return  array             Possible array members: day, month, year, hour, minute, second, fixed, format
  */
 private static function _parseDate($date, $options)
 {
     if (!is_string($date)) {
         throw new Exception('Invalid date provided; must be string, ' . gettype($date) . ' provided');
     }
     $options = self::_checkOptions($options) + self::$_options;
     $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v');
     $format = $options['date_format'];
     $number = $date;
     // working copy
     $result['date_format'] = $format;
     // save the format used to normalize $number (convenience)
     $result['locale'] = $options['locale'];
     // save the locale used to normalize $number (convenience)
     $oenc = iconv_get_encoding('internal_encoding');
     iconv_set_encoding('internal_encoding', 'UTF-8');
     $day = iconv_strpos($format, 'd');
     $month = iconv_strpos($format, 'M');
     $year = iconv_strpos($format, 'y');
     $hour = iconv_strpos($format, 'H');
     $min = iconv_strpos($format, 'm');
     $sec = iconv_strpos($format, 's');
     $am = null;
     if ($hour === false) {
         $hour = iconv_strpos($format, 'h');
     }
     if ($year === false) {
         $year = iconv_strpos($format, 'Y');
     }
     if ($day === false) {
         $day = iconv_strpos($format, 'E');
         if ($day === false) {
             $day = iconv_strpos($format, 'D');
         }
     }
     if ($day !== false) {
         $parse[$day] = 'd';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // erase day string
             $daylist = Data::getList($options['locale'], 'day');
             if (is_scalar($number)) {
                 foreach ($daylist as $key => $name) {
                     if (iconv_strpos($number, $name) !== false) {
                         $number = str_replace($name, "EEEE", $number);
                         break;
                     }
                 }
             }
         }
     }
     $position = false;
     if ($month !== false) {
         $parse[$month] = 'M';
         if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) {
             // prepare to convert month name to their numeric equivalents, if requested,
             // and we have a $options['locale']
             $position = self::_replaceMonth($number, Data::getList($options['locale'], 'month'));
             if ($position === false) {
                 $position = self::_replaceMonth($number, Data::getList($options['locale'], 'month', array('gregorian', 'format', 'abbreviated')));
             }
         }
     }
     if ($year !== false) {
         $parse[$year] = 'y';
     }
     if ($hour !== false) {
         $parse[$hour] = 'H';
     }
     if ($min !== false) {
         $parse[$min] = 'm';
     }
     if ($sec !== false) {
         $parse[$sec] = 's';
     }
     if (empty($parse)) {
         iconv_set_encoding('internal_encoding', $oenc);
         throw new Exception("Unknown date format, neither date nor time in '" . $format . "' found");
     }
     ksort($parse);
     // get daytime
     if (iconv_strpos($format, 'a') !== false) {
         if (iconv_strpos(strtoupper($number), strtoupper(Data::getContent($options['locale'], 'am'))) !== false) {
             $am = true;
         } else {
             if (iconv_strpos(strtoupper($number), strtoupper(Data::getContent($options['locale'], 'pm'))) !== false) {
                 $am = false;
             }
         }
     }
     // split number parts
     $split = false;
     preg_match_all('/\\d+/u', $number, $splitted);
     if (count($splitted[0]) == 0) {
         iconv_set_encoding('internal_encoding', $oenc);
         throw new Exception("No date part in '{$date}' found.");
     }
     if (count($splitted[0]) == 1) {
         $split = 0;
     }
     $cnt = 0;
     foreach ($parse as $key => $value) {
         switch ($value) {
             case 'd':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['day'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['day'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'M':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['month'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['month'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'y':
                 $length = 2;
                 if (iconv_substr($format, $year, 4) == 'yyyy' || iconv_substr($format, $year, 4) == 'YYYY') {
                     $length = 4;
                 }
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['year'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['year'] = iconv_substr($splitted[0][0], $split, $length);
                     $split += $length;
                 }
                 ++$cnt;
                 break;
             case 'H':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['hour'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['hour'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 'm':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['minute'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['minute'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
             case 's':
                 if ($split === false) {
                     if (count($splitted[0]) > $cnt) {
                         $result['second'] = $splitted[0][$cnt];
                     }
                 } else {
                     $result['second'] = iconv_substr($splitted[0][0], $split, 2);
                     $split += 2;
                 }
                 ++$cnt;
                 break;
         }
     }
     // AM/PM correction
     if ($hour !== false) {
         if ($am === true and $result['hour'] == 12) {
             $result['hour'] = 0;
         } else {
             if ($am === false and $result['hour'] != 12) {
                 $result['hour'] += 12;
             }
         }
     }
     if ($options['fix_date'] === true) {
         $result['fixed'] = 0;
         // nothing has been "fixed" by swapping date parts around (yet)
     }
     if ($day !== false) {
         // fix false month
         if (isset($result['day']) and isset($result['month'])) {
             if ($position !== false and (iconv_strpos($date, $result['day']) === false or isset($result['year']) and iconv_strpos($date, $result['year']) === false)) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     throw new Exception("Unable to parse date '{$date}' using '" . $format . "' (false month, {$position}, {$month})");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 1;
             }
         }
         // fix switched values d <> y
         if (isset($result['day']) and isset($result['year'])) {
             if ($result['day'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     throw new Exception("Unable to parse date '{$date}' using '" . $format . "' (d <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['day'];
                 $result['day'] = $temp;
                 $result['fixed'] = 2;
             }
         }
         // fix switched values M <> y
         if (isset($result['month']) and isset($result['year'])) {
             if ($result['month'] > 31) {
                 if ($options['fix_date'] !== true) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     throw new Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> y)");
                 }
                 $temp = $result['year'];
                 $result['year'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 3;
             }
         }
         // fix switched values M <> d
         if (isset($result['month']) and isset($result['day'])) {
             if ($result['month'] > 12) {
                 if ($options['fix_date'] !== true || $result['month'] > 31) {
                     iconv_set_encoding('internal_encoding', $oenc);
                     throw new Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> d)");
                 }
                 $temp = $result['day'];
                 $result['day'] = $result['month'];
                 $result['month'] = $temp;
                 $result['fixed'] = 4;
             }
         }
     }
     if (isset($result['year'])) {
         if (iconv_strlen($result['year']) == 2 && $result['year'] < 10 || (iconv_strpos($format, 'yy') !== false && iconv_strpos($format, 'yyyy') === false || iconv_strpos($format, 'YY') !== false && iconv_strpos($format, 'YYYY') === false)) {
             if ($result['year'] >= 0 && $result['year'] < 100) {
                 if ($result['year'] < 70) {
                     $result['year'] = (int) $result['year'] + 100;
                 }
                 $result['year'] = (int) $result['year'] + 1900;
             }
         }
     }
     iconv_set_encoding('internal_encoding', $oenc);
     return $result;
 }
Beispiel #4
0
function performTests()
{
    global $failed, $test_output, $action, $admin_db_failed, $public_db_failed, $admin_dsn, $public_dsn, $smarty, $global_dd, $alm_connect;
    $failed = false;
    $red = '<font color="red">FALL&Oacute;</font>';
    $green = '<font color="green">PAS&Oacute;</font>';
    # Old versions don't use admin_dsn public_dsn but simply a DSN constant
    if (!isset($admin_dsn)) {
        $admin_dsn = DSN;
    }
    if (!isset($public_dsn)) {
        $public_dsn = DSN;
    }
    $test_output .= "Probando conexion a base de datos (public)... ";
    unset($alm_connect[$public_dsn]);
    $db = almdata::connect($public_dsn);
    if (almdata::basicError($db, $public_dsn) || !$alm_connect[$public_dsn]) {
        $error_msg = almdata::basicError($db, $public_dsn);
        $test_output .= "{$red} <i>{$error_msg}</i><br/>";
        $failed = true;
        $public_db_failed = true;
    } else {
        $test_output .= "{$green}<br/>";
    }
    # Check admin connection last, so that we stay admin...
    $test_output = "Probando conexion a base de datos (admin)... ";
    unset($alm_connect[$admin_dsn]);
    $db = almdata::connect($admin_dsn);
    if (almdata::basicError($db, $admin_dsn) || !$alm_connect[$admin_dsn]) {
        $error_msg = almdata::basicError($db, $admin_dsn);
        $test_output .= "{$red} <i>{$error_msg}</i><br/>";
        $failed = true;
        $admin_db_failed = true;
    } else {
        $test_output .= "{$green}<br/>";
    }
    $test_output .= "Probando configuracion de PHP... ";
    if (get_cfg_var('short_open_tag') != 1) {
        $test_output .= "{$red} <i>short_open_tag = " . get_cfg_var('short_open_tag') . "</i><br/>";
        $failed = true;
    } else {
        $test_output .= "{$green}<br/>";
    }
    $test_output .= "Probando permisos de directorios... ";
    if (checkPerms($smarty->compile_dir) !== true) {
        $test_output .= "{$red} <i> {$smarty->compile_dir} = " . checkPerms($smarty->compile_dir) . "</i><br/>";
    }
    if (checkPerms($smarty->cache_dir) !== true) {
        $test_output .= "{$red} <i> {$smarty->cache_dir} = " . checkPerms($smarty->cache_dir) . "</i><br/>";
    }
    $logs_dir = ROOTDIR . '/logs';
    if (checkPerms($logs_dir) !== true) {
        $test_output .= "{$red} <i> {$logs_dir} = " . checkPerms($logs_dir) . "</i><br/>";
    }
    $files_dir = ROOTDIR . '/files';
    if (checkPerms($files_dir) !== true) {
        $test_output .= "{$red} <i> {$files_dir} = " . checkPerms($files_dir) . "</i><br/>";
    }
    if (checkPerms($smarty->compile_dir) === true && checkPerms($smarty->cache_dir) === true) {
        $test_output .= "{$green}<br/>";
    } else {
        $failed = true;
    }
    $test_output .= "Dónde está almidón? ";
    if (defined('ALMIDONDIR')) {
        $test_output .= '<font color="green">' . ALMIDONDIR . '</font><br/>';
    } else {
        $failed = true;
        $test_output .= $red;
    }
    $test_output .= "BD Almidonizada? ";
    list($type, $tmp) = preg_split('/:\\/\\//', $admin_dsn);
    if ($type == 'pgsql') {
        $sqlcmd = "SELECT relname FROM pg_class WHERE  pg_class.relkind = 'r' AND pg_class.relname LIKE 'alm_%'";
    } elseif ($type == 'mysql') {
        $sqlcmd = "SHOW TABLES LIKE 'alm_%';";
    }
    $data = new Data();
    $var = @$data->getList($sqlcmd);
    if (count($var) >= 5) {
        $test_output .= '<font color="green">' . print_r($var, 1) . '</font>';
    } else {
        #$failed = true;
        $test_output .= $red;
    }
    if ($failed) {
        $action = 'failed';
        $test_output .= '<br/><br/><font color="red">Por favor corregir antes de continuar con la instalaci&oacute;n</font>';
    }
}