示例#1
0
/**
 * Converts PHP array to its Javascript analog
 *
 * @access private
 * @param  array     PHP array to convert
 * @param  bool      Generate Javascript object literal (default, works like PHP's associative array) or array literal
 * @return string    Javascript representation of the value
 */
function convertArrayToJavascript($array, $assoc = true)
{
    if (!is_array($array)) {
        return $convertScalarToJavascript($array);
    } else {
        $items = array();
        foreach ($array as $key => $val) {
            $item = $assoc ? "'" . escapeString($key) . "': " : '';
            if (is_array($val)) {
                $item .= convertArrayToJavascript($val, $assoc);
            } else {
                $item .= convertScalarToJavascript($val);
            }
            $items[] = $item;
        }
    }
    $js = implode(', ', $items);
    return $assoc ? '{ ' . $js . ' }' : '[' . $js . ']';
}
示例#2
0
 /**
  * Outputs the java script used by the page.
  */
 public function javascript()
 {
     if (isset($_SESSION['search_params'])) {
         $sp = $_SESSION['search_params'];
     } else {
         $sp = new pdSearchParams();
     }
     $pos = strpos($_SERVER['PHP_SELF'], 'papersdb');
     $url = substr($_SERVER['PHP_SELF'], 0, $pos) . 'papersdb';
     // WICK
     $this->js .= "\ncollection=" . convertArrayToJavascript($this->db_authors, false) . "\n";
     $js_file = 'js/advanced_search.js';
     assert('file_exists($js_file)');
     $content = file_get_contents($js_file);
     // adjust date information if user did not enter all the fields
     if (!isset($sp->startdate['Y'])) {
         $sp->startdate['Y'] = pdPublication::MIN_YEAR;
     }
     if (!isset($sp->startdate['M'])) {
         $sp->startdate['M'] = '1';
     }
     if (!isset($sp->enddate['Y'])) {
         $sp->enddate['Y'] = pdPublication::MAX_YEAR;
     }
     if (!isset($sp->enddate['M'])) {
         $sp->enddate['M'] = '12';
     }
     $this->js .= str_replace(array('{host}', '{self}', '{selected_authors}', '{cat_id}', '{title}', '{authors}', '{paper}', '{abstract}', '{venue}', '{keywords}', '{paper_rank_other}', '{startdateY}', '{startdateM}', '{enddateY}', '{enddateM}', '{paper_rank1}', '{paper_rank2}', '{paper_rank3}', '{paper_rank4}', '{paper_col1}', '{paper_col2}', '{paper_col3}', '{paper_col4}', '{author_myself}', '{show_internal_info}', '{have_user_info}', '{user_info}'), array($_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'], $sp->authors, $sp->cat_id, $sp->title, $sp->authors, $sp->paper, $sp->abstract, $sp->venue, $sp->keywords, $sp->paper_rank_other, $sp->startdate['Y'], $sp->startdate['M'], $sp->enddate['Y'], $sp->enddate['M'], isset($sp->paper_rank[1]) ? $sp->paper_rank[1] == 'yes' : FALSE, isset($sp->paper_rank[2]) ? $sp->paper_rank[2] == 'yes' : FALSE, isset($sp->paper_rank[3]) ? $sp->paper_rank[3] == 'yes' : FALSE, isset($sp->paper_rank[4]) ? $sp->paper_rank[4] == 'yes' : FALSE, isset($sp->paper_col[1]) ? $sp->paper_col[1] == 'yes' : FALSE, isset($sp->paper_col[2]) ? $sp->paper_col[2] == 'yes' : FALSE, isset($sp->paper_col[3]) ? $sp->paper_col[3] == 'yes' : FALSE, isset($sp->paper_col[4]) ? $sp->paper_col[4] == 'yes' : FALSE, isset($_SESSION['user']) ? $sp->author_myself != '' : FALSE, isset($_SESSION['user']) ? $sp->show_internal_info == 'yes' : FALSE, isset($_SESSION['user']) && $_SESSION['user']->showInternalInfo() ? 'true' : 'false', isset($_SESSION['user']) ? $sp->user_info : ""), $content);
     $this->addJavascriptFiles(array('js/wick.js', 'js/check_authors.js'));
 }
示例#3
0
 private function javascript()
 {
     // WICK
     $this->js .= "\ncollection=" . convertArrayToJavascript($this->db_authors, false) . "\n";
     $this->addJavascriptFiles(array('../js/wick.js', '../js/check_authors.js'));
 }
示例#4
0
    public function javascript()
    {
        $pos = strpos($_SERVER['PHP_SELF'], 'papersdb');
        $url = substr($_SERVER['PHP_SELF'], 0, $pos) . 'papersdb';
        // WICK/
        $this->js .= "\ncollection=" . convertArrayToJavascript($this->authors, false) . ";\n\n";
        $this->js .= <<<JS_END
window.addEvent('domready', function() {
        var Tips1 = new Tips(\$\$('.Tips1'));
    });
JS_END;
        $js_files = array('js/add_pub_cancel.js');
        foreach ($js_files as $js_file) {
            assert('file_exists($js_file)');
            $content = file_get_contents($js_file);
            $this->js .= str_replace(array('{host}', '{self}', '{new_location}'), array($_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'], $url), $content);
        }
        $this->addJavascriptFiles(array('../js/wick.js', '../js/check_authors.js'));
    }