Пример #1
0
function draw_svg($pie_id, $base_name, $args)
{
    global $output_dir;
    global $svg_template;
    global $bg_schemes;
    $bar_start = 48;
    $bar_end = 312.4;
    $bar_len = $bar_end - $bar_start;
    $svg_output = $output_dir . $base_name . '.svg';
    if (file_exists($svg_output)) {
        return $svg_output;
    }
    // Parse
    $xdoc = new DomDocument();
    $xdoc->Load($svg_template);
    $xp = new DomXPath($xdoc);
    // Get progress from DB
    $result = pg_query("SELECT state FROM pieces WHERE pie = " . $pie_id);
    $states = pg_fetch_all_columns($result, 0);
    $progress = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $full_sum = 9 * count($states);
    $current_sum = 0;
    foreach ($states as $st) {
        $progress[$st]++;
        $current_sum += $st;
    }
    // Calculate bars positions and widths
    $offset = $bar_start;
    $step = $bar_len / count($states);
    for ($i = 0; $i <= 9; $i++) {
        $elem = find_by_id($xp, 'bar_' . $i);
        $elem->setAttribute('x', $offset);
        $elem->setAttribute('width', $step * $progress[$i]);
        $offset += $step * $progress[$i];
    }
    // Set percent
    $percent = round($current_sum / $full_sum * 100);
    find_by_id($xp, 'percent-fg')->nodeValue = $percent . '%';
    // Set BG color gradient;
    $current_bg_scheme = $bg_schemes['middle'];
    if ($progress[9] / count($states) > 0.6) {
        $current_bg_scheme = $bg_schemes['high'];
    } else {
        if ($progress[0] / count($states) > 0.6) {
            $current_bg_scheme = $bg_schemes['low'];
        }
    }
    find_by_id($xp, 'bg-grd-start')->setAttribute('style', 'stop-color:#' . $current_bg_scheme[0] . ';stop-opacity:1');
    find_by_id($xp, 'bg-grd-stop')->setAttribute('style', 'stop-color:#' . $current_bg_scheme[1] . ';stop-opacity:1');
    // Save it to file
    if (($fd = fopen($svg_output, 'w')) === false) {
        throw new Exception("Cant open SVG file for saving");
    }
    fwrite($fd, $xdoc->saveXML());
    fclose($fd);
    return $svg_output;
}
Пример #2
0
 function manyToOneQuery($ar)
 {
     $z = extract($ar);
     //$act=($this->useWiki) ? ' WHERE active>0 ' : '';
     $SQL = "SELECT DISTINCT {$many} FROM " . $this->tabl;
     $rZ = $this->xQuery($SQL, 0);
     $aList = compileList(',', pg_fetch_all_columns($rZ));
     pg_free_result($rZ);
     $act = $useWiki ? 'WHERE active>0 AND ' : 'WHERE ';
     $SQL = "SELECT DISTINCT {$key},{$var} FROM {$tabl} {$act} " . "{$key} IN (" . implode(',', $aList) . ")";
     return $SQL;
 }
Пример #3
0
function _update_users_claims($res, $from, $to_all)
{
    global $connection;
    $user_list = array('user_list', array());
    $claim_list = array('claim_list', array());
    // Buffer array
    $users = array();
    $result = pg_query($connection, 'SELECT pieces.id, pieces.index, users.nick, users.color FROM pieces JOIN users ON users.id = pieces.owner WHERE pie = ' . $from->pieid . ' ORDER BY pieces.index');
    $piece_ids = pg_fetch_all_columns($result, 0);
    // Users who has pieces
    while ($row = pg_fetch_assoc($result)) {
        if (isset($users[$row['nick']])) {
            $users[$row['nick']]['owns'][] = $row['index'];
        } else {
            $users[$row['nick']] = array('owns' => array($row['index']), 'color' => array($row['color']), 'online' => false);
        }
    }
    if (count($piece_ids) != 0) {
        $result = pg_query($connection, 'SELECT claims.id, users.nick, users.color, pieces.index, score FROM claims JOIN pieces on claims.piece = pieces.id JOIN users ON users.id = claims.author WHERE piece IN (' . implode(',', $piece_ids) . ')');
        while ($row = pg_fetch_assoc($result)) {
            $claim_list[1][] = array('claim_id' => $row['id'], 'piece_index' => $row['index'], 'vote_balance' => $row['score'], 'owner' => $row['nick']);
            // Users who has claims
            if (!isset($users[$row['nick']])) {
                $users[$row['nick']] = array('owns' => array(), 'color' => array($row['color']), 'online' => false);
            }
        }
    }
    // Adding all online users:  chat_members JOIN users
    $result = pg_query($connection, 'SELECT users.id, users.nick, users.color FROM chat_members LEFT JOIN users ON users.id = member WHERE pie = ' . $from->pieid);
    while ($row = pg_fetch_assoc($result)) {
        // If new user -> set it fully
        if (!isset($users[$row['nick']])) {
            $users[$row['nick']] = array('owns' => array(), 'color' => array($row['color']));
        }
        $users[$row['nick']]['online'] = true;
    }
    // Generating user_list from userbuffer array
    foreach ($users as $user_nick => $attrs) {
        $user_list[1][] = array('user_nick' => $user_nick, 'color' => $attrs['color'], 'reserved' => $attrs['owns'], 'online' => $attrs['online']);
    }
    if ($to_all) {
        $res->to_pie($from, $user_list);
        $res->to_pie($from, $claim_list);
    } else {
        $res->to_sender($user_list);
        $res->to_sender($claim_list);
    }
}
Пример #4
0
 public function as_array($key = NULL, $value = NULL)
 {
     if ($this->_total_rows === 0) {
         return array();
     }
     if (!$this->_as_object and $key === NULL) {
         // Rewind
         $this->_current_row = 0;
         if ($value === NULL) {
             // Indexed rows
             return pg_fetch_all($this->_result);
         }
         // Indexed columns
         return pg_fetch_all_columns($this->_result, pg_field_num($this->_result, $value));
     }
     return parent::as_array($key, $value);
 }
 function ChangeBuckets()
 {
     global $SysConf;
     global $PG_CONN;
     $uploadId = GetParm("upload", PARM_STRING);
     $uploadTreeId = GetParm("item", PARM_STRING);
     $sql = "SELECT bucketpool_fk from bucket_ars where upload_fk = {$uploadId};";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $bucketpool_array = pg_fetch_all_columns($result, 0);
     pg_free_result($result);
     $buckets_dir = $SysConf['DIRECTORIES']['MODDIR'];
     /** rerun bucket on the file */
     foreach ($bucketpool_array as $bucketpool) {
         $command = "{$buckets_dir}/buckets/agent/buckets -r -t {$uploadTreeId} -p {$bucketpool}";
         exec($command);
     }
 }
Пример #6
0
 public function selectCol($query)
 {
     $result = call_user_func_array([$this, 'query'], func_get_args());
     return pg_fetch_all_columns($result, 0);
 }
Пример #7
0
 /**
  * fetchColumn
  *
  * Fetch a column from a result.
  *
  * @access public
  * @param  string $name
  * @return array
  */
 public function fetchColumn($name)
 {
     return pg_fetch_all_columns($this->handler, $this->getFieldNumber($name));
 }
Пример #8
0
/**
 * \brief Gets the list of jobqueue records with the requested $status 
 *
 * \param string $status - the status might be:
 *        Started, Completed, Restart, Failed, Paused, etc
 *        the status 'Started' and 'Restart', you can call them as running status
 *        to get all the running job list, you can set the $status as 'tart'
 *
 * \return job list related to the jobstatus,
 *         the result is like: Array(1, 2, 3, .., i), sorted
 **/
function GetJobList($status)
{
    /* Gets the list of jobqueue records with the requested $status */
    global $PG_CONN;
    if (empty($status)) {
        return;
    }
    $sql = "SELECT jq_pk FROM jobqueue WHERE jq_endtext like '%{$status}%' order by jq_pk;";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $job_array = pg_fetch_all_columns($result, 0);
    pg_free_result($result);
    return $job_array;
}
Пример #9
0
function getDBColumn_SQL($SQL)
{
    $r = newQuery($SQL, 0);
    $ar = pg_fetch_all_columns($r, 0);
    pg_free_result($r);
    return $ar;
}
Пример #10
0
</table>
<br />
<?php 
//run query
if (isset($_REQUEST["SearchBtn"])) {
    $ret = pg_exec($db_handle, $new_str);
    if (!$ret) {
        echo "<br />Query Failed!\n";
        var_dump($ret);
    } else {
        //print out table containing the query
        $record_found = pg_numrows($ret);
        echo "<p>{$record_found} records found!</p>";
        $q_array = pg_fetch_all_columns($ret, 3);
        $region_array = pg_fetch_all_columns($ret, 1);
        $id_array = pg_fetch_all_columns($ret, 0);
        echo "<table border=1 bgcolor='white' cellspacing=7 cellpadding=2>";
        echo "<tr><th>\"State\"</th><th>\"Region\"</th><th>\"Link\"</th></tr>";
        for ($i = 0; $i < count($q_array); $i++) {
            if (strlen($q_array[$i]) == 0) {
                $str_out = "UNKNOWN";
            } else {
                $str_out = $q_array[$i];
            }
            echo "<tr><td>{$str_out}</td>";
            if (strlen($region_array[$i]) == 0) {
                $str_out2 = "UNKNOWN";
            } else {
                $str_out2 = $region_array[$i];
            }
            echo "<td>{$str_out2}</td>";
Пример #11
0
function _update_user_reserved($res, $from, $user_id, $nick)
{
    global $connection;
    $result = pg_query($connection, 'SELECT index FROM pieces WHERE owner = ' . $user_id . ' and pie = ' . $from->pieid . ' ORDER BY index');
    $piece_indexes = pg_fetch_all_columns($result, 0);
    if ($piece_indexes === false) {
        $piece_indexes = array();
    }
    $res->to_pie($from, array('user_update', array('current_nick' => $nick, 'reserved' => $piece_indexes)));
}
 /**
  * Selects records and return values (first field) as an array using a SQL statement.
  *
  * @param string $sql The SQL query
  * @param array $params array of sql parameters
  * @return array of values
  * @throws dml_exception A DML specific exception is thrown for any errors.
  */
 public function get_fieldset_sql($sql, array $params = null)
 {
     list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
     $this->query_start($sql, $params, SQL_QUERY_SELECT);
     $result = pg_query_params($this->pgsql, $sql, $params);
     $this->query_end($result);
     $return = pg_fetch_all_columns($result, 0);
     pg_free_result($result);
     return $return;
 }
Пример #13
0
function display_menubar()
{
    if (!isset($_SESSION['athlete_id'])) {
        echo <<<ENDHTML
\t<H2>Your session has expired</H2>
\t<FONT size=1>Please <a href=index.php >return to the <u>login page</u> and log in again.<a></FONT><br>
ENDHTML;
        exit;
    }
    $login = $_SESSION['login'];
    $athlete_id = $_SESSION['athlete_id'];
    require_once "access_check.php";
    $filename = basename(__FILE__);
    #access_check( $filename ) ;
    // Connect to DB
    include_once "sql_functions.php";
    #$dbconn = pg_connect("host=localhost dbname=training_diary user=athlete password=ironman")
    # or die('Could not connect: ' . pg_last_error());
    $query = "SELECT name from athlete WHERE athlete_id = {$athlete_id}";
    #$result = pg_query($query) or die('Query failed: ' . pg_last_error());
    $result = do_sql($query);
    $row = pg_fetch_array($result, null, PGSQL_ASSOC);
    $firstname = $row['name'];
    $query = "SELECT function FROM user_access WHERE athlete_id = '{$athlete_id}'";
    $result = do_sql($query) or die('Query failed: ' . pg_last_error());
    $allowed = pg_fetch_all_columns($result, 0);
    echo <<<HTMLEND

<TABLE>
<TR><TD align=right class=fitnessmad  >
<b><font size=3 color=#885555 >
<i> FitnessMad.Net </i>
</FONT><br/>
<font color=#AA5555 >
Training Log
</FONT>
</b>
</TD><TD class=mainmenu align=right valign=bottom >
&nbsp;&nbsp;&nbsp; 
You are logged in {$firstname}<br>
</TD>
</TR>
</TABLE>

<HR>
HTMLEND;
    echo <<<ENDHTML

  <TABLE><TR><TD>
  <UL class="nav">

ENDHTML;
    // Assume we want to jump to today's date, won't do anything if
    // this is not in the date range selected.
    $jumpto = "anchorD" . date("Ymd");
    // View My Log
    if (in_array("view_log.php", $allowed)) {
        echo <<<HTMLEND

  <LI class=menuheader ><a href="view_log.php#{$jumpto}"> View My Log</a> 
  </LI>

HTMLEND;
    }
    // Add Log Entry
    $date = date("d/m/Y");
    if (in_array("add_log_entry.php", $allowed)) {
        echo <<<HTMLEND

  <LI class=menuheader >
    <!-- <a href="javascript:launchRemote('add_log_entry.php#{$jumpto}')" >  -->
    <a href="javascript:launchRemote('add_log_entry.php?start_date={$date}')" >
    Add Log entry</a>
  </LI>

HTMLEND;
    }
    // Start dropdown menu for Configuration options
    echo <<<CONFIGMENU

    <li class=menuheader ><a >Configuration</a>
    <ul>

CONFIGMENU;
    if (in_array("configure_view.php", $allowed)) {
        echo <<<CONFIGMENU

\t<li><a href="configure_view.php">
\t\tConfigure View</a></li>

CONFIGMENU;
    }
    if (in_array("configure_log_entry.php", $allowed)) {
        echo <<<CONFIGMENU

\t<li><a href="configure_log_entry.php">
\t\tConfigure Log Entry Fields</a></li>

CONFIGMENU;
    }
    if (in_array("configure_exercise_types.php", $allowed)) {
        echo <<<CONFIGMENU

    \t<li><a href="configure_exercise_types.php">
\t\tConfigure Exercise Types</a></li>
    \t</ul>
    \t</li>

CONFIGMENU;
    }
    //User admin Menu
    echo <<<USERMENU

   <li class=menuheader ><a>User</a>
   <ul>

USERMENU;
    if (in_array("change_password.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a  href="change_password.php" >Change Password</a>
\t</LI>

HTMLEND;
    }
    if (in_array("newuser.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a  href="newuser.php" > Add New User</a> 
\t</LI>

HTMLEND;
    }
    if (in_array("configure_share_permissions.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a  href="configure_share_permissions.php" >
  \tConfigure Shared Access</a>
\t</LI>

HTMLEND;
    }
    if (in_array("configure_security_access.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a  href="configure_security_access.php" >
  Configure User Access</a>
\t</LI>

HTMLEND;
    }
    if (in_array("access_other_user.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a   href="access_other_user.php">
  View Other Athlete's Log</a>
\t</LI>

HTMLEND;
    }
    if (in_array("see_who_is_online.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a   href="see_who_is_online.php">
  Currently Connected Users</a>
\t</LI>

HTMLEND;
    }
    if (in_array("view_login_log.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a   href="view_login_log.php">
  View log of recent logins</a>
\t</LI>

HTMLEND;
    }
    if (in_array("logout.php", $allowed)) {
        echo <<<HTMLEND

\t<LI><a   href="logout.php" >
  Logout</a>
\t</LI>

HTMLEND;
    }
    echo <<<ENDUSER

  </UL>
  </LI>

ENDUSER;
    if (in_array("logout.php", $allowed)) {
        echo <<<HTMLEND

\t<LI class=menuheader ><a href="logout.php">
  \tLogout</a>
\t</LI>

HTMLEND;
    }
    echo <<<HTMLEND

\t<LI class=menuheader ><a href="loggedin.php" >
\tHelp</a>
\t</LI>

HTMLEND;
    echo <<<HTMLEND

  </LI>
 </UL>
</TD></TR></TABLE>


HTMLEND;
    //END of function display_menubar
}
Пример #14
0
 function is_authentified()
 {
     global $DB;
     $res = $DB->tab_result("SELECT * FROM admin_svg.utilisateur WHERE login = '******' AND psw = '" . $this->pass . "';");
     if (count($res) == 0) {
         return 0;
     } else {
         $this->insee = $res[0]['idcommune'];
         $res2 = $DB->tab_result("SELECT idagglo FROM admin_svg.commune WHERE idcommune = '" . $res[0]['idcommune'] . "';");
         $this->idagglo = $res2[0]['idagglo'];
         $this->idutilisateur = $res[0]['idutilisateur'];
         $this->droit = $res[0]['droit'];
         $this->droit_appli = "";
         $this->acces_ssl = true;
         $res1 = pg_query($DB->con, "select application.libelle_appli from admin_svg.application inner join admin_svg.apputi on admin_svg.application.idapplication=admin_svg.apputi.idapplication join admin_svg.utilisateur on admin_svg.apputi.idutilisateur=admin_svg.utilisateur.idutilisateur where apputi.idutilisateur='" . $res[0]['idutilisateur'] . "' order by application.type_appli asc;");
         $this->liste_appli = pg_fetch_all_columns($res1, 0);
         $this->roles[] = 2;
         if ($res[0]['droit'] == 'AD') {
             // FIXME: affiner la gestion des droits
             $this->roles[] = 1;
         }
         return 1;
     }
 }
Пример #15
0
 function getRowList()
 {
     if ($this->useWiki) {
         $useAct = ' WHERE active>0 ';
     } else {
         $useAct = '';
     }
     $wh = $this->sqlSubset();
     if ($wh and !$useAct) {
         $useAct = ' WHERE ';
     } elseif ($wh) {
         $useAct .= ' AND ';
     } else {
         $nought = 0;
     }
     if ($wh) {
         $useAct .= $wh;
     }
     $r = $this->xQuery("SELECT " . $this->indx . "," . $this->getDisplayText() . " FROM " . $this->tabl . " {$useAct} ORDER BY " . $this->getDisplayText() . ";", 1);
     $ids = pg_fetch_all_columns($r, 0);
     $names = pg_fetch_all_columns($r, 1);
     pg_free_result($r);
     return array_combine($ids, $names);
 }
Пример #16
0
 /**
  * Выбрать колонку из БД.
  *
  * @return unknown
  */
 public function fetchColumn()
 {
     $this->select_prepare();
     $result = pg_query($this->connection, $this->query);
     if (!$result) {
         trigger_error('Select error: ' . pg_last_error($this->connection), E_USER_ERROR);
     }
     return pg_fetch_all_columns($result);
 }
Пример #17
0
function sql_assoc($query, $back)
{
    global $db;
    if (DEBUG) {
        echo "<br>{$query}";
    }
    $result = pg_query($db, $query) or die("Erreur pgSQL : " . $query);
    unset($query);
    if ($back) {
        for ($i = 0; $i < pg_num_fields($result); $i++) {
            $colname = pg_field_name($result, $i);
            $ligne[$colname] = pg_fetch_all_columns($result, $i);
        }
    } else {
        $ligne = array();
    }
    pg_free_result($result);
    return $ligne;
}
Пример #18
0
$app->get('/delete/', function () use($app) {
    $_con = getDBConnection();
    $sqlresult = pg_query($_con, 'DELETE FROM tones');
    pg_close($_con);
    return $app['twig']->render('echo_tone.twig', array('tone' => 'all tone deleted'));
});
//get tone list
$app->get('/get/tonelist/', function () use($app) {
    $result;
    $_con = getDBConnection();
    $sqlresult = pg_query($_con, 'SELECT id,tone FROM tones ORDER BY created desc');
    if (!$sqlresult) {
        echo "An error occurred.\n";
        exit;
    }
    $arr = pg_fetch_all_columns($sqlresult, 1);
    pg_close($_con);
    return $app['twig']->render('echo_tone.twig', array('tone' => implode(',', $arr)));
});
//get tone list as json
$app->get('/get/tonelist/json/', function () use($app) {
    $result;
    $_con = getDBConnection();
    $sqlresult = pg_query($_con, 'SELECT id,tone FROM tones ORDER BY created desc');
    //$sqlresult = pg_query($_con, "SELECT array_to_json( array_agg(tones)) FROM tones");
    if (!$sqlresult) {
        echo "An error occurred.\n";
        exit;
    }
    $arr = pg_fetch_all($sqlresult);
    pg_close($_con);
Пример #19
0
 public function FetchAll(int $column = NULL)
 {
     return is_null($column) ? pg_fetch_all($this->ds) : pg_fetch_all_columns($this->ds, $column);
 }
Пример #20
0
	/**
	 * query and fetch all rows at once
	 *
	 * @param string  $sql
	 * @return array
	 */
	public static function fetchfieldarray($sql) {
		$result = self::query($sql);
		$fieldarray = pg_fetch_all_columns($result);
		pg_free_result($result);
		return $fieldarray;
	}
 /**
  * Selects records and return values (first field) as an array using a SQL statement.
  *
  * @param string $sql The SQL query
  * @param array $params array of sql parameters
  * @return array of values
  * @throws dml_exception A DML specific exception is thrown for any errors.
  */
 public function get_fieldset_sql($sql, array $params = null)
 {
     list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
     $this->query_start($sql, $params, SQL_QUERY_SELECT);
     $result = pg_query_params($this->pgsql, $sql, $params);
     $this->query_end($result);
     $return = pg_fetch_all_columns($result, 0);
     if (pg_field_type($result, 0) == 'bytea') {
         foreach ($return as $key => $value) {
             $return[$key] = $value === null ? $value : pg_unescape_bytea($value);
         }
     }
     pg_free_result($result);
     return $return;
 }
Пример #22
0
<?php

header("Access-Control-Allow-Origin: *");
$dbconn = pg_connect("host=localhost dbname=01_20 port=5432 user=postgres password=admin ") or die('Could not connect: ' . pg_last_error());
if ($stat == PGSQL_CONNECTION_OK) {
    // echo 'jobb egy lud nyak ket tyuk nyaknal';
} else {
    echo 'Connection status bad';
}
$query = "SELECT r_id FROM ho_building";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$out = pg_fetch_all_columns($result);
$myarr = json_encode($out);
echo $myarr;
Пример #23
0
 public function resultQueryAV($statement)
 {
     $data = ($keys = pg_fetch_all_columns($res = pg_query($this->db, $statement))) ? array_combine($keys, pg_fetch_all_columns($res, 1)) : [];
     pg_free_result($res);
     return $data;
 }
Пример #24
0
 public static function find_all_column_values($sql, $idx)
 {
     global $database;
     $get_cols = self::find_by_sql($sql);
     $column_arr = pg_fetch_all_columns($get_cols, $idx);
     return $column_arr;
 }