/**
  * execute the connection to source
  **/
 function connect()
 {
     $this->close();
     list($task_name) = each($_POST['action']['run_task']);
     $query = "SELECT `last_execution`" . " FROM " . $GLOBALS['prefix_fw'] . "_task" . " WHERE `name` = '" . $task_name . "'";
     list($last_execution) = sql_fetch_row(sql_query($query));
     $this->last_execution = $last_execution;
     $string = str_replace('[blank_space],', '', $this->param_string);
     $string = str_replace(',[blank_space]', '', $string);
     $string .= ',[id_course],[date_creation]';
     $array_cols = explode(',', $string);
     $array_to_unset = array();
     foreach ($array_cols as $key => $value) {
         $last = strlen($value);
         if ($last > 3) {
             $last--;
             if ($value[0] !== '[' || $value[$last] !== ']') {
                 $array_to_unset[] = $key;
             }
         } else {
             $array_to_unset[] = $key;
         }
     }
     reset($array_cols);
     foreach ($array_to_unset as $unset_key) {
         unset($array_cols[$unset_key]);
     }
     $array_cols = array_unique($array_cols);
     $this->cols_descriptor = $array_cols;
     /* search for file with pattern */
     $pat = str_replace(array("*", "?"), array(".*", ".{1}"), $this->filename);
     $arr_files = preg_ls(DOCEBOIMPORT_BASEDIR, false, '/' . $pat . '/');
     $this->curr_file = DOCEBOIMPORT_BASEDIR . $pat;
     //print_r($this->filename);
     /* open file */
     $this->filehandle = @fopen($this->curr_file, 'w');
     if ($this->filehandle === FALSE) {
         $this->last_error = 'file not opened: ' . $this->curr_file;
         return FALSE;
     }
     return true;
 }
Beispiel #2
0
 public function menu()
 {
     static $menu = null;
     if ($menu !== null) {
         return $menu;
     }
     // List templates, provide links.
     $base = $this->container->config['templates_base'];
     $templates = preg_ls($base, true, '/\\.tpl\\.php$/');
     $this->html_body = '';
     $request = $_SERVER['REQUEST_URI'];
     asort($templates);
     foreach ($templates as $_) {
         $_ = substr($_, strlen($base));
         if (substr($_, 0, 1) == '_') {
             continue;
         }
         $_ = str_replace('.tpl.php', '', $_);
         $menu .= "<li><a href=\"{$_SERVER['SCRIPT_NAME']}?tpl=" . urlencode($_) . "\" >" . htmlspecialchars($_) . "</a></li>";
     }
     $menu = "<ul class=\"styler-menu\">{$menu}</ul>";
     return $menu;
 }
Beispiel #3
0
function preg_ls($path = ".", $rec = FALSE, $pat = "/.*/", $ignoredir = '')
{
    while (substr($path, -1, 1) == "/") {
        $path = substr($path, 0, -1);
    }
    if (!is_dir($path)) {
        $path = dirname($path);
    }
    if ($rec !== TRUE) {
        $rec = FALSE;
    }
    $d = dir($path);
    $ret = array();
    while (FALSE !== ($e = $d->read())) {
        if ($e == "." || $e == "..") {
            continue;
        }
        if ($rec && is_dir($path . "/" . $e) && ($ignoredir == '' || strpos($ignoredir, $e) === FALSE)) {
            $ret = array_merge($ret, preg_ls($path . "/" . $e, $rec, $pat, $ignoredir));
            continue;
        }
        if (!preg_match($pat, $e)) {
            continue;
        }
        $ret[] = $path . "/" . $e;
    }
    return empty($ret) && preg_match($pat, basename($path)) ? array($path . "/") : $ret;
}
Beispiel #4
0
 /**
  * An ls style command using regular expresions
  * 
  * By fordiman@gmail.com taken from PHP documentation:
  * http://www.php.net/manual/en/class.dir.php#60562
  *
  * @example foreach (preg_ls("/etc/X11", true, "/.*\.conf/i") as $file) echo $file."\n";
  * @param string $path
  * @param boolean $recursive if the ls should be recursive
  * @param string $patttern the pattern in regular expression format
  * @return Array
  */
 public static function preg_ls($path = ".", $recursive = false, $pattern = "/.*/")
 {
     $rec = $recursive;
     $pat = $pattern;
     // it's going to be used repeatedly, ensure we compile it for speed.
     $pat = preg_replace("|(/.*/[^S]*)|s", "\\1S", $pat);
     //Remove trailing slashes from path
     while (substr($path, -1, 1) == "/") {
         $path = substr($path, 0, -1);
     }
     //also, make sure that $path is a directory and repair any screwups
     if (!is_dir($path)) {
         $path = dirname($path);
     }
     //assert either truth or falsehoold of $rec, allow no scalars to mean truth
     if ($rec !== true) {
         $rec = false;
     }
     //get a directory handle
     $d = dir($path);
     //initialise the output array
     $ret = array();
     //loop, reading until there's no more to read
     while (false !== ($e = $d->read())) {
         //Ignore parent- and self-links
         if ($e == "." || $e == "..") {
             continue;
         }
         //If we're working recursively and it's a directory, grab and merge
         if ($rec && is_dir($path . "/" . $e)) {
             $ret = array_merge($ret, preg_ls($path . "/" . $e, $rec, $pat));
             continue;
         }
         //If it don't match, exclude it
         if (!preg_match($pat, $e)) {
             continue;
         }
         //In all other cases, add it to the output array
         $ret[] = $path . "/" . $e;
     }
     //finally, return the array
     return $ret;
 }
Beispiel #5
0
 function _step1()
 {
     $enclosure = htmlentities($this->post_params['field_enclosure']);
     $out = $this->form->getLineBox($this->lang->def('_FIELD_DELIMITER'), $this->post_params['field_delimiter']);
     $out .= $this->form->getLineBox($this->lang->def('_FIELD_ENCLOSURE'), $enclosure);
     if ($this->post_params['field_def_type'] == '2') {
         $path = $GLOBALS['where_files_relative'] . '/common/iofiles/' . $this->post_params['subpattern'];
         $pat = str_replace(array("*", "?"), array(".*", ".{1}"), $this->post_params['filepattern']);
         $arr_files = preg_ls($path, false, '/' . $pat . '/');
         if (count($arr_files) == 0) {
             $this->post_params['field_def'] = array("File not found: " . $pat);
         } else {
             $hfile = @fopen($arr_files[0], 'r');
             if ($hfile === FALSE) {
                 $this->post_params['field_def'] = array("File not open: " . $arr_files[0]);
             } else {
                 $this->post_params['field_def'] = fgetcsv($hfile, 1024, $this->post_params['field_delimiter'], $this->post_params['field_enclosure']);
                 $out .= $this->form->getLineBox($this->lang->def('_FILE_ANALYZED'), basename($arr_files[0]));
                 fclose($hfile);
             }
         }
     }
     $field_def = $enclosure . implode($enclosure . $this->post_params['field_delimiter'] . $enclosure, $this->post_params['field_def']) . $enclosure;
     $out .= $this->form->getTextfield($this->lang->def('_FIELD_DEF'), $this->_get_base_name() . '_field_def', $this->_get_base_name() . '[field_def]', 1024, $field_def);
     return $out;
 }