function avg_lifetime($query_name,$pattern,$qreplace) { $r=get_queries($query_name); $r=replace_queries($r,$pattern,$qreplace); $res=SQL_select($r[0]['replaced_query']); $days=floor($res[0]['res']/(60*24)); $hours=round(($res[0]['res']/60)-$days*24,0); $avg=array(); $avg['days']=$days; $avg['hours']=$hours; return $avg; }
// Comparison function based on mutual friend count function cmp($a, $b) { if ($a['count'] == $b['count']) { return 0; } return $a['count'] < $b['count'] ? 1 : -1; } if ($user) { try { // Proceed knowing you have a logged in user who's authenticated. $user_profile = $facebook->api('/me'); echo "<pre>"; $response = get_friends(); //array_splice($response, 50); $queries = get_queries($response); $BATCH_SIZE = 50; $batches = array_chunk($queries, $BATCH_SIZE); $i = 0; foreach ($batches as $batch) { try { $mutual = $facebook->api('/?batch=' . json_encode($batch), 'POST'); foreach ($mutual as $idx => $dict) { $body = $dict['body']; $arr = json_decode($body); $response[$i * $BATCH_SIZE + $idx]['count'] = count($arr); } } catch (FacebookApiException $e) { print_r($e); } $i++;
/** * @date 20120306 (v1.1) (greg) support in-query relaxed error code * * To state that a sql query can fail on certains code, start the query with a special comment : * / *[1061]* /CREATE UNIQUE INDEX `index` USING BTREE ON `pds_core_menu_structure`(`menu_id`) ; * (remove the space between slashes and stars) * multiple codes can be separated with commas, NO SPACES allowed * * Common MySQL error codes: * * [1061] Duplicate key name 'index' * [1091] Can't DROP 'field'; check that column/key exists * [1068] Multiple primary key defined */ function stuffMYSQL() { global $data, $doit, $type, $db_version, $version; // Going deeper, lets see if we can make a db connection. $connect_mysql = mysql_connect($data['db_server'], $data['db_username'], $data['db_password']); if (empty($connect_mysql)) { addError(kMYSQLconnect, sprintf(_('Unable to connect to the MySQL database %s, please make sure you entered all the relevant details correctly and that the MySQL server is currently running.'), mysql_error())); return false; } // Check if we can select our database. if (!mysql_select_db($data['db_name'])) { addError(kMYSQLselectDB, sprintf(_('Unable to select the specified database (%s). please make sure you entered all the relevant details correctly. The database should exists and be accessible by the user provided'), $data['db_name'])); return false; } // Check if the databas is not perhaps already installed. $tables = @mysql_list_tables($data['db_name']); $tables = @mysql_numrows($tables); if ($type == 'install') { if (!empty($tables)) { addError(kMYSQLnotempty, _('There are tables in this database already, perhaps a previous PHPDevShell installation?. This Installation script can not be used over an existing PHPDevShell installation.')); return false; } } else { if ($type == 'upgrade') { if (empty($tables)) { addError(kMYSQLempty, _('There are no existing tables in this database, are you sure PHPDevShell is installed?.')); return false; } $phpds_db_ver = get_db_version(); if ($phpds_db_ver == $db_version) { addError(kMYSQLuptodate, sprintf(_('<strong><span style="color: green">This specific upgrade version does not require database updates, system is running the latest current db version DB-%s which is used for %s. Try again when next update is released.</span></strong>'), $phpds_db_ver, $version)); return false; } } } // Check if the database version is up to date. if (mysql_get_server_info() < '5.0') { addError(kMYSQLversion, sprintf(_('This version of PHPDevShell only supports MySQL version %s and later. You are currently running version %s.'), '5.0', mysql_get_server_info())); return false; } displayDBfilling(); print "\n\n"; ob_flush(); flush(); // Installation can now commence! $queries = get_queries(); // Loop and execute queries. $i = 0; $max = count($queries); mysql_query('START TRANSACTION'); $e = mysql_errno(); if (!$e) { foreach ($queries as $query) { if (!empty($query) && $doit) { if (!mysql_query($query)) { $em = mysql_error(); } usleep(1000); } else { usleep(1000); } if (connection_aborted()) { error_log('aborted'); exit; } if ($e = mysql_errno()) { $matches = array(); if (preg_match('#^\\s*/\\*\\[([\\d\\,]+)\\]\\*/(.*)$#', $query, $matches)) { $accepted = explode(',', $matches[1]); if (in_array($e, $accepted)) { noticePrint(_('Accepting error') . ' ' . $e . ' ("' . $matches[2] . '")'); } else { break; } } else { break; } } $i++; $p = intval($i * 100 / $max); if (!empty($debug_queries)) { if (strpos($query, '#') === false) { messagePrint($query . " <strong>({$p}%)</strong>"); } else { okPrint($query . " <strong>({$p}%)</strong>"); } } if ($i % 10 == 0) { print "<script type=\"text/javascript\">updateProgress({$p});</script>\n\n"; ob_flush(); flush(); } } } if ($e) { mysql_query('ROLLBACK'); $error = sprintf(_('An error occured trying to send the queries (query %d/%d).'), $i, $max); $error .= '<br />' . _('The error was') . ': [' . $e . '] ' . $em; $error .= '<br />' . _('The offending query was') . ': "' . $query . '"'; addError(kMYSQLquery, $error); return false; } print "<script type=\"text/javascript\">updateProgress(100);</script>\n\n"; ob_flush(); flush(); mysql_query('COMMIT'); return true; }
$month=$today['mon']; //days set $days=$monthes[$month-1]['month_duration']; $xtpl->assign("SECTION_NAME", "Statistics: Managers work for ".$monthes[$month-1]['month_name']." ".$year); //user set if ( (isset($_POST['user'])) and ($_POST['user'])!=0 ) { $user=$_POST['user']; //main part: get from db, replace and execute queries $r=get_queries('answers_ud','closed_ud','complains_ud','comments_ud'); $r=replace_queries($r,array("#year#","#month#","#user#"),array($year,$month,$user)); $d=do_queries_d($r,$days); //drawing diagrams foreach ($d as $dn=>$dv) { $s=''; foreach ($r as $rk=>$rv ) { if (isset($dv[$rv['q_html_title']])) { $title=$dv[$rv['q_html_title']]; $height=$title*2; $xtpl->assign("TD_CONTENT",'<a href="stat_tickets.php?uname='.$users[$user].'&user='******'&day='.$dn.'&month='.$month.'&year='.$year.'&type='.$rv['q_html_title'].'">'.$dv[$rv['q_html_title']].'</a>'); }
/** * return error message as string, or true indicating success * requires setup to be written first. */ function setup_database() { $conn = DB_Helper::getInstance(false); $db_exists = checkDatabaseExists($conn, $_POST['db_name']); if (!$db_exists) { if (@$_POST['create_db'] == 'yes') { try { $conn->query("CREATE DATABASE {{{$_POST['db_name']}}}"); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('create_db', $e->getMessage())); } } else { throw new RuntimeException('The provided database name could not be found. Review your information or specify that the database should be created in the form below.'); } } // create the new user, if needed if (@$_POST['alternate_user'] == 'yes') { $user_list = getUserList($conn); if ($user_list) { $user_exists = in_array(strtolower(@$_POST['eventum_user']), $user_list); if (@$_POST['create_user'] == 'yes') { if (!$user_exists) { $stmt = "GRANT SELECT, UPDATE, DELETE, INSERT, ALTER, DROP, CREATE, INDEX ON {{{$_POST['db_name']}}}.* TO ?@'%' IDENTIFIED BY ?"; try { $conn->query($stmt, array($_POST['eventum_user'], $_POST['eventum_password'])); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('create_user', $e->getMessage())); } } } else { if (!$user_exists) { throw new RuntimeException('The provided MySQL username could not be found. Review your information or specify that the username should be created in the form below.'); } } } } // check if we can use the database try { $conn->query("USE {{{$_POST['db_name']}}}"); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('select_db', $e->getMessage())); } // set sql mode (sad that we rely on old bad mysql defaults) $conn->query("SET SQL_MODE = ''"); // check the CREATE and DROP privileges by trying to create and drop a test table $table_list = getTableList($conn); if (!in_array('eventum_test', $table_list)) { try { $conn->query('CREATE TABLE eventum_test (test char(1))'); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('create_test', $e->getMessage())); } } try { $conn->query('DROP TABLE eventum_test'); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('drop_test', $e->getMessage())); } // if requested. drop tables first if (@$_POST['drop_tables'] == 'yes') { $queries = get_queries(APP_PATH . '/upgrade/drop.sql'); foreach ($queries as $stmt) { try { $conn->query($stmt); } catch (DbException $e) { throw new RuntimeException(getErrorMessage('drop_table', $e->getMessage())); } } } // setup database with upgrade script $buffer = array(); try { $dbmigrate = new DbMigrate(APP_PATH . '/upgrade'); $dbmigrate->setLogger(function ($e) use(&$buffer) { $buffer[] = $e; }); $dbmigrate->patch_database(); $e = false; } catch (Exception $e) { } global $tpl; $tpl->assign('db_result', implode("\n", $buffer)); if ($e) { $upgrade_script = APP_PATH . '/upgrade/update-database.php'; $error = array('Database setup failed on upgrade:', "<tt>{$e->getMessage()}</tt>", '', "You may want run update script <tt>{$upgrade_script}</tt> manually"); throw new RuntimeException(implode('<br/>', $error)); } // write db name now that it has been created $setup = array(); $setup['database'] = $_POST['db_name']; // substitute the appropriate values in config.php!!! if (@$_POST['alternate_user'] == 'yes') { $setup['username'] = $_POST['eventum_user']; $setup['password'] = $_POST['eventum_password']; } Setup::save(array('database' => $setup)); }
if(array_key_exists("searching_parameters", $_SESSION)) unset($_SESSION["searching_parameters"]); $cond1 = array("appear"=>"appear", "not appear"=>"not appear"); $cond2 = array("contain"=>"contain","not contain"=>"not contain","appear"=>"appear", "not appear"=>"not appear"); //query formation if (isset($_GET['user'])) { $r=get_queries($_GET['type'].'_for1day_u'); $r=replace_queries($r,array("#year#","#month#","#day#","#user#"),array($_GET['year'],$_GET['month'],$_GET['day'],$_GET['user'])); $xtpl->assign("SECTION_NAME", "You are viewing ".$_GET['type']." tickets for ".$_GET['day']."-".$_GET['month']."-".$_GET['year']." which were maded by ".$_GET['uname']); } else { $r=get_queries($_GET['type'].'_for1day'); $r=replace_queries($r,array("#year#","#month#","#day#"),array($_GET['year'],$_GET['month'],$_GET['day'])); $xtpl->assign("SECTION_NAME", "You are viewing ".$_GET['type']." tickets for ".$_GET['day']."-".$_GET['month']."-".$_GET['year']); } $query=$r[0]['replaced_query']; $xtpl->assign("TABLE_HEADER", '<td class="table_header_text" align="center">#</td><td class="table_header_text" align="center"><a href="#" onclick="return false" onmouseup="select_all_checkboxs(\'select[]\',\'form1\')" class="table_header_text">Select</a></td><td align="center" class="table_header_text">Subject</td><td align="center" class="table_header_text">Queues</td><td align="center" class="table_header_text">Status</td><td align="center" class="table_header_text">Owner</td><td class="table_header_text" align="center">From</td><td align="center" class="table_header_text">Complain</td><td align="center" class="table_header_text">Rate</td><td class="table_header_text" align="center">Updated</td><td align="center" class="table_header_text">Created</td> '); $pg_sel=SQL_select($query); foreach($pg_sel as $i=>$row) { $xtpl->assign("NUM", ($i+1)); $xtpl->assign("_ID", $i); $xtpl->assign("TICKET_ID", $row["id"]); $xtpl->assign("SELECT", "<input type=\"checkbox\" id=\"" . $i . "\" name=\"select[]\" value=\"" . $row["id"] . "\" onclick=\"change_tr_class(this)\">");
//monthes $mquery="SELECT * FROM monthes"; $monthes=SQL_select($mquery); $today=getdate(); //year set if ( (isset($_POST['year'])) and ($_POST['year'])!=0 ) $year=$years[$_POST['year']]; else $year=$today['year']; $xtpl->assign("SECTION_NAME", "Statistics: Summary for ".$year." year"); //main part: get from db, replace and execute queries $r=get_queries('answers_y','closed_y','new_y','complains_y','comments_y'); $r=replace_queries($r,array("#year#"),array($year)); $d=do_queries_d($r,12); //drawing diagrams foreach ($d as $dn=>$dv) { $s=''; foreach ($r as $rk=>$rv ) { if (isset($dv[$rv['q_html_title']])) { $title=$dv[$rv['q_html_title']]; $height=$title/6; $xtpl->assign("TD_CONTENT",$dv[$rv['q_html_title']]); }
<div class="buttons"> <button type="submit">Next</button> </div> </form> </div></div>'; break; case 5: // INSTALL DB $check = false; // db connection $dsn = empty($_SESSION['dbsocket']) ? 'mysql:host=' . $_SESSION['dbhost'] . ';dbname=' . $_SESSION['dbname'] : 'mysql:unix_socket=' . $_SESSION['dbsocket'] . ';dbname=' . $_SESSION['dbname']; $db = new PDO($dsn, $_SESSION['dbuser'], $_SESSION['dbpass'], array(PDO::ATTR_PERSISTENT => 'x3cms', PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'")); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // get sql $query = get_queries(FINAL_ROOT . 'cms/files/' . $_SESSION['tmp']); $body = '<div class="one-whole padded lightgray clearfix"> <a href="./index.php" title="Back to Intro">Intro</a> ' . SPACER . ' <a href="./index.php?s=1" title="Back to License agreement">Step 1</a> ' . SPACER . ' <a href="./index.php?s=2" title="Back to Requirements check">Step 2</a> ' . SPACER . ' <a href="./index.php?s=3" title="Back to Permissions check">Step 3</a> ' . SPACER . ' <a href="./index.php?s=4" title="Back to Configuration">Step 4</a> <span> + Step 5/5</span> </div> </div> <div class="band bgray lightgray clearfix pad-top"> <div class="one-third push-one-third md-one-half md-push-one-fourth sm-one-whole sm-push-none pad-left pad-right">