function parseFile($file, $type) { $sql = new MySQL(); $sql->connect('127.0.0.1', 'root', 'root'); $objReader = PHPExcel_IOFactory::createReader($type); $chunkSize = 200; $i = 1; $sql->clear('price_liga'); $r = array(); for ($startRow = 0; $startRow <= 5000; $startRow += $chunkSize + 1) { $chunkFilter = new chunkReadFilter($startRow, $chunkSize); $objReader->setReadFilter($chunkFilter); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($file); $data = $objPHPExcel->getActiveSheet()->toArray(); foreach ($data as $k => $v) { if ($data[$k][0] == '') { unset($data[$k]); } else { $sql->insert('price_liga', array('id' => $i, 'cat_num' => $data[$k][0], 'brand' => ucwords(strtolower($data[$k][1])), 'article' => $data[$k][2], 'descr' => str_replace("'", "\\'", $data[$k][3]), 'model' => str_replace("'", "\\'", $data[$k][4]), 'size' => $data[$k][5], 'price' => $data[$k][6], 'amount' => $data[$k][8]), true); $i++; } } } //print_r($r); $sql->close(); return array('counter' => $i); }
function parseFile($file, $type) { $sql = new MySQL(); $sql->connect('127.0.0.1', 'root', 'root'); $objReader = PHPExcel_IOFactory::createReader($type); $chunkSize = 200; $i = 1; $sql->clear('price_v8'); for ($startRow = 0; $startRow <= 5000; $startRow += $chunkSize + 1) { $chunkFilter = new chunkReadFilter($startRow, $chunkSize); $objReader->setReadFilter($chunkFilter); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($file); $data = $objPHPExcel->getActiveSheet()->toArray(); foreach ($data as $k => $v) { if (trim($data[$k][0]) == 'Артикул' || $data[$k][3] == '' || strstr($data[$k][3], 'камера') || $data[$k][7] == '') { unset($data[$k]); } else { $descr = str_replace('Ш', 'xSTUDEDx', trim($data[$k][3])); $descr = preg_replace('/[а-яА-Я]/', '', $descr); $sql->insert('price_v8', array('id' => $i, 'article' => trim($data[$k][0]), 'descr' => str_replace("'", "\\'", $descr), 'cat_num' => trim($data[$k][6]), 'season' => trim($data[$k][7]), 'price' => trim($data[$k][9]), 'amount' => trim(preg_replace('/[а-яА-Яa-zA-Z]{0,}/', '', $data[$k][10]))), true); $i++; } } } $sql->close(); return array('counter' => $i); }
function validationmail($email) { require_once 'mysql/mysql.php'; require 'mysql/mysql_settings.php'; //Build mysql connection $mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db); //Create request $request = 'INSERT INTO validationmails(email) VALUES ("' . $email . '");'; //Perform request $response = $mysql->insert($request); //Check if request was successfull if (!$response) { $echo = mysqli_error($mysql->getCon()); } else { $id = $mysql->insert_id; } return email($email, ' Hi ' . $user . ', um loszulegen klick einfach auf den Link und los geht\'s! http://fragdichab.de/?p=1&id=' . $id . '&req=validation Sch�ne Gr��e, Ruben & Jannes ', 'Bestaetigungsmail'); }
function register($email, $password, $username) { require_once 'mysql/mysql.php'; require 'mysql/mysql_settings.php'; /** * Establish new connection * Check if email is already registered * If so give out failure message, otherwise give out success */ $mysql = new MySQL($mysql_user, $mysql_pw, $mysql_server, $mysql_db); /** *Check if email is registered */ $request = 'SELECT user.idUser FROM user WHERE user.email="' . $email . '";'; $response = $mysql->request($request); $response = json_decode(json_encode($response), true); //If so return failure message if (!empty($response)) { $echo = 'invalid email'; return $echo; } /** * If not put user into database */ $request = 'INSERT INTO user(name,password,email,valid) VALUES ("' . $username . '","' . $password . '","' . $email . '",0);'; $response = $mysql->insert($request); //Check if insertion worked out if (!$response) { $echo = mysqli_error($mysql->getCon()); } else { $echo = 'done'; } //Return result return $echo; }
public static function signup($user) { $mysql = new MySQL(); $id = $mysql->insert("user", $user); $mysql->closeCon(); return $id; }
public static function insertDiscuss($disObj) { $mysql = new MySQL(); $res = $mysql->insert("page_discs", $disObj); $mysql->closeCon(); PageService::updateDisNum($disObj['pageid']); return $res; }
/** * This function will compress data for storage in `tbl_cache`. * It is left to the user to define a unique hash for this data so that it can be * retrieved in the future. Optionally, a `$ttl` parameter can * be passed for this data. If this is omitted, it data is considered to be valid * forever. This function utilizes the Mutex class to act as a crude locking * mechanism. * * @see toolkit.Mutex * @param string $hash * The hash of the Cached object, as defined by the user * @param string $data * The data to be cached, this will be compressed prior to saving. * @param integer $ttl * A integer representing how long the data should be valid for in seconds. * By default this is null, meaning the data is valid forever * @return boolean * If an error occurs, this function will return false otherwise true */ public function write($hash, $data, $ttl = null) { if (!Mutex::acquire($hash, 2, TMP)) { return false; } $creation = time(); $expiry = null; $ttl = intval($ttl); if ($ttl > 0) { $expiry = $creation + $ttl * 60; } if (!($data = $this->compressData($data))) { return false; } $this->forceExpiry($hash); $this->Database->insert(array('hash' => $hash, 'creation' => $creation, 'expiry' => $expiry, 'data' => $data), 'tbl_cache'); Mutex::release($hash, TMP); return true; }
public function testFlush() { $connection = new MySQL(self::$pdo); $data1 = array('id' => 1, 'username' => 'username1'); $data2 = array('id' => 2, 'username' => 'username2'); $data3 = array('id' => 3, 'username' => 'username3'); $connection->insert('user', $data1); $connection->insert('user', $data2); $connection->insert('user', $data3); $stmt = self::$pdo->prepare('SELECT COUNT(*) AS count FROM user'); $stmt->execute(); $count = $stmt->fetchColumn(); $stmt->closeCursor(); $this->assertEquals(3, $count); $connection->flush('user'); $stmt = self::$pdo->prepare('SELECT COUNT(*) AS count FROM user'); $stmt->execute(); $count = $stmt->fetchColumn(); $stmt->closeCursor(); $this->assertEquals(0, $count); }
function parseFile($file, $type) { $sql = new MySQL(); $sql->connect('127.0.0.1', 'root', 'root'); $objReader = PHPExcel_IOFactory::createReader($type); $sheets = $objReader->listWorksheetNames($file); $i = 1; $sql->clear('price_moscow'); foreach ($sheets as $sheet) { $chunkSize = 200; if (strstr($sheet, 'Шины')) { $r = array(); for ($startRow = 0; $startRow <= 4000; $startRow += $chunkSize + 1) { $chunkFilter = new chunkReadFilter($startRow, $chunkSize); $objReader->setReadFilter($chunkFilter); $objReader->setReadDataOnly(true); $objReader->setLoadSheetsOnly($sheet); $objPHPExcel = $objReader->load($file); $data = $objPHPExcel->getActiveSheet()->toArray(); foreach ($data as $k => $v) { if ($data[$k][2] == '' || $data[$k][2] == 'Модель') { unset($data[$k]); } else { $season = strstr($data[$k][7], 'Летняя') ? 0 : (strstr($data[$k][7], 'Зимняя') ? 1 : 2); $vtype = strstr($data[$k][8], 'Легковая') ? 0 : (strstr($data[$k][8], 'Грузовая') ? 1 : 2); $stunds = $data[$k][10] == '' || $data[$k][10] == 'Нет' ? 0 : 1; $xl = $data[$k][12] == '' || $data[$k][12] == 'Нет' ? 0 : 1; $runflat = $data[$k][13] == '' || $data[$k][13] == 'Нет' ? 0 : 1; $sql->insert('price_moscow', array('id' => $i, 'article' => trim($data[$k][0]), 'brand' => ucwords(strtolower(trim($data[$k][1]))), 'model' => str_replace("'", "\\'", trim($data[$k][2])), 'width' => trim($data[$k][3]), 'height' => trim($data[$k][4]), 'diameter' => (int) preg_replace('/[a-zA-Z]/', '', trim($data[$k][5])), 'weight_speed' => trim($data[$k][6]), 'season' => $season, 'v_type' => $vtype, 'studs' => $stunds, 'xl' => $xl, 'runflat' => $runflat, 'price_rrc' => $data[$k][17], 'price_opt' => $data[$k][18], 'amount' => 0), true); $i++; } } } } } $sql->close(); return array('counter' => $i); }
$current_city = isset($_POST['city']) ? $_POST['city'] : ''; $gender = isset($_POST['gender']) ? $_POST['gender'] : ''; $bmonth = isset($_POST['bmonth']) ? $_POST['bmonth'] : ''; $bday = isset($_POST['bday']) ? $_POST['bday'] : ''; $byear = isset($_POST['byear']) ? $_POST['byear'] : ''; if (empty($hometown)) { $hometown = $current_city; } list($firstname, $middlename, $lastname) = split(' ', $name); if (!isset($lastname)) { $lastname = $middlename; $middlename = ''; } try { $db = new MySQL(); $db->insert('login', array('username' => $username, 'access_level' => 1, 'last_login' => date('Y-m-d'), 'date_joined' => date('Y-m-d'), 'logins' => 1)); $user_id = $db->insertID(); $db->query('UPDATE login SET pass = PASSWORD("' . mysql_real_escape_string($password) . '") WHERE user_id = ' . $user_id); $db->insert('info', array('user_id' => $user_id, 'firstname' => $firstname, 'middlename' => $middlename, 'lastname' => $lastname, 'email' => $email, 'gender' => $gender, 'hometown' => $hometown, 'current_city' => $current_city, 'birth_month' => $bmonth, 'birth_day' => $bday, 'birth_year' => $byear)); $db->insert('socialhns', array('user_id' => $user_id)); if (LOCAL) { $db->insert('hns_desktop', array('user_id' => $user_id)); $db->insert('homenetspaces', array('user_id' => $user_id)); } if ($db->affectedRows() == 1) { $_SESSION['logged'] = true; $_SESSION['user_id'] = $user_id; $_SESSION['username'] = $username; $_SESSION['access_level'] = 1; $_SESSION['last_login'] = date('Y-m-d'); if (isset($middlename) && !empty($middlename)) {
$community = isset($_POST['city']) ? $_POST['city'] : ''; $gender = isset($_POST['gender']) ? $_POST['gender'] : ''; $bmonth = isset($_POST['bmonth']) ? $_POST['bmonth'] : ''; $bday = isset($_POST['bday']) ? $_POST['bday'] : ''; $byear = isset($_POST['byear']) ? $_POST['byear'] : ''; if (empty($community)) { $community = $hometown; } list($firstname, $middlename, $lastname) = split(' ', $name); if (!$lastname) { $lastname = $middlename; unset($middlename); } try { $db = new MySQL(); $db->insert(array('username' => $username, 'password' => $password, 'access_level' => 1, 'last_login' => date('Y-m-d'), 'date_joined' => date('Y-m-d'), 'last_login_ip' => $ip), 'login'); $db->insert(array('user_id' => $db->insertID(), 'firstname' => $firstname, 'middlename' => $middlename, 'lastname' => $lastname, 'email' => $email, 'gender' => $gender, 'hometown' => $hometown, 'community' => $community, 'birth_month' => $bmonth, 'birth_day' => $bday, 'birth_year' => $byear, 'logins' => 1)); } catch (Exception $e) { echo $e->getMessage(); exit; } loggedIn(); } if (isset($_GET['p'])) { if ($_GET['p'] == 'username') { try { $db = new MySQL(); $db->query('SELECT username FROM login WHERE username = "******"'); echo $db->numRows(); } catch (Exception $e) { echo $e->getMessage();
$db->sfquery(array('SELECT * FROM misc WHERE username = "******" AND pass = PASSWORD("%s") LIMIT 1',$_POST['username'],$_POST['password'])); if ($db->numRows() > 0) { $row = $db->fetchAssocRow(); loggedIn($row); } else die('0'); } catch(Exception $e) { echo $e->getMessage(); exit(); } } elseif (isset($_POST['register'])) { $username = (isset($_POST['username'])) ? $_POST['username'] : ''; $password = (isset($_POST['password'])) ? $_POST['password'] : ''; try { $db = new MySQL(); $db->insert('misc', array( 'username'=>$username, 'date_joined'=>date('Y-m-d'), )); $user_id = $db->insertID(); $db->query('UPDATE misc SET pass = PASSWORD("'.mysql_real_escape_string($password).'") WHERE user_id = '.$user_id); if ($db->affectedRows() == 1) { $_SESSION['logged'] = true; $_SESSION['user_id'] = $user_id; $_SESSION['username'] = $username; die('true'); } else die('false'); } catch(Exception $e) { echo $e->getMessage(); exit(); } loggedIn(); }
} else { if ($action == 'submit_deljob') { $DB = new MySQL(Loader::$config['dbconf']['main']['dbname'], Loader::$config['dbconf']['main']['user'], Loader::$config['dbconf']['main']['passwd'], Loader::$config['dbconf']['main']['host'], Loader::$config['dbconf']['main']['port']); $sql = "update curweekjob set enable=0 where id=" . $req; $ret = $DB->executeSQL($sql); if (!$ret) { echo json_encode(array('ret' => 'false', '更新失败!')); die; } echo json_encode(array('ret' => 'true', '更新成功!')); } else { if ($action == 'submit_addlastjob') { $DB = new MySQL(Loader::$config['dbconf']['main']['dbname'], Loader::$config['dbconf']['main']['user'], Loader::$config['dbconf']['main']['passwd'], Loader::$config['dbconf']['main']['host'], Loader::$config['dbconf']['main']['port']); $val = array('job' => $req['job'], 'classmate' => $req['classmate'], 'process' => $req['process'], 'teamname' => $req['teamname'], 'plantime' => json_encode($req['plantime'])); $datatypes = array('str', 'str', 'int', 'str', 'str'); $ret = $DB->insert("lastweekjob", $val, '', $datatypes); if (!$ret) { echo json_encode(array('ret' => 'false', '更新失败!')); die; } echo json_encode(array('ret' => 'true', '更新成功!')); } else { if ($action == 'submit_dellastjob') { $DB = new MySQL(Loader::$config['dbconf']['main']['dbname'], Loader::$config['dbconf']['main']['user'], Loader::$config['dbconf']['main']['passwd'], Loader::$config['dbconf']['main']['host'], Loader::$config['dbconf']['main']['port']); $sql = "update lastweekjob set enable=0 where id=" . $req; $ret = $DB->executeSQL($sql); if (!$ret) { echo json_encode(array('ret' => 'false', '更新失败!')); die; } echo json_encode(array('ret' => 'true', '更新成功!'));
COLLATE=\'utf8_bin\' ENGINE=MyISAM;'; if (defined('UPGRADE')) { $sql = 'ALTER TABLE `vm` ADD COLUMN `vz_id` INT(10) NOT NULL DEFAULT \'0\' AFTER `vm_id`, ADD INDEX `idx_vz_id` (`vz_id`); ALTER TABLE `user` ADD INDEX `idx_name` (`name`), ADD INDEX `idx_language` (`language`), ADD INDEX `idx_date_created` (`date_created`);'; } $db->executeSQL($sql); // Create administrator if (!defined('UPGRADE')) { $db->insert('user', array('is_admin' => 1, 'is_active' => 1, 'name' => $_SESSION['name'], 'email_address' => $_SESSION['email_address'], 'password' => hashed($_SESSION['password']), 'language' => $_SESSION['language'], 'date_created' => date('Y-m-d H:i:s'))); } $configurations = '<?php define(\'INSTALLED\', 1); define(\'SVMC_VERSION\', \'' . $version . '\'); $config[\'dbHost\'] = \'' . $data->dbHost . '\'; $config[\'dbUser\'] = \'' . $data->dbUser . '\'; $config[\'dbPass\'] = \'' . $data->dbPass . '\'; $config[\'dbName\'] = \'' . $data->dbName . '\'; $config[\'language\'] = \'' . $_SESSION['language'] . '\'; ?>'; file_put_contents(ROOT . 'configuration.php', $configurations); if (defined('UPGRADE')) { $out .= '<h1>' . UPGRADE_COMPLETED . '</h1>
if ($cat_id == 0) { foreach ($GLOBALS['news_cat'] as $cur_cat) { if ($cur_cat['web_id'] != $org_id) { continue; } if ($org_id != $dst_id) { $db->update($setting['db']['pre'] . "news_cat", array("web_id" => $dst_id), array("cat_id", "n=", $cur_cat['cat_id'])); } $db->select($pre_org . "news_show", "*", array("cat_id", "n=", $cur_cat['cat_id']), array("order" => "news_id asc")); $id_list = array(); while ($record = $db->GetRS()) { $the_id = array(); $the_id['old'] = $record['news_id']; $record['news_id'] = 0; $record['web_id'] = $dst_id; $db2->insert($pre_dst . "news_show", $record, true); $the_id['new'] = $db2->GetInsertId(); $id_list[] = $the_id; } for ($i = 0, $m = count($id_list); $i < $m; $i++) { if ($id_list[$i]['new'] == 0) { break; } $db->select($pre_org . "news_detail", "*", array("news_id", "n=", $id_list[$i]['old']), array("order" => "news_id asc, page asc")); while ($record = $db->GetRS()) { $record['id'] = 0; $record['news_id'] = $id_list[$i]['new']; $db2->insert($pre_dst . "news_detail", $record, true); } $db->delete($pre_org . "news_show", array("news_id", "n=", $id_list[$i]['old'])); $db->delete($pre_org . "news_detail", array("news_id", "n=", $id_list[$i]['old']));
header("Content-type: text/html; charset=utf-8"); session_start(); set_time_limit(0); require_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'Config.php'; require_once dirname(dirname(dirname(__FILE__))) . PATH . "includes" . PATH . 'dao' . PATH . 'MySQL.php'; $data = $_POST['dd']; if (!empty($data)) { $mysql = new MySQL(); $objs = json_decode($data); // echo count($objs);exit; foreach ($objs as $d) { $insertData['phrase'] = $d->phrase; $insertData['type'] = $d->type; $insertData['url'] = $d->url; $insertData['hot'] = $d->hot; $insertData['common'] = $d->common; $insertData['category'] = $d->category; $insertData['icon'] = $d->icon; $insertData['value'] = $d->value; $insertData['picid'] = $d->picid; // var_dump($insertData); $id = $mysql->insert("emotion", $insertData); echo "id=" . $id . " "; } $mysql->closeCon(); echo json_encode("解析成功"); exit; } else { echo json_encode("没有数据"); }
if ($db2['create_T']) { echo "<br>Creating Tables ... "; $SQL->change_db($db2['dbase']); include "database.php"; while (list(, $q) = each($table)) { # echo "<br>".$q; if (!$SQL->query($q)) { die("<br>Error while doing: " . $q . " -> " . $SQL->error_msg); } } echo GOOD; } // Create Admin User if ($db2['create_AU']) { echo "<br>Creating Admin User with (admin and adminpass) ... "; $SQL->insert("INSERT INTO `" . $prefix . "press_user` ( `id` , `name` , `pass` , `counter` , `session` , `auth` ) VALUES ('', 'admin', '" . sha1("adminpass") . "', '0', '', '0');"); $SQL->insert("INSERT INTO `" . $prefix . "press_admins` ( `id` ) VALUES ('1');"); echo GOOD; } // writing mysql_zugangsdaten into file.. echo "<br>Schreibe Konfigurationsdatei '" . CONFIGFILE . "' ... "; $fh = fopen(CONFIGFILE, "w"); if (fwrite($fh, "[db]\n" . "user=\"" . $db2['user'] . "\"\n" . "pass=\"" . $db2['pass'] . "\"\n" . "dbase=\"" . $db2['dbase'] . "\"\n" . "tableprefix=\"" . $prefix . "\"\n" . "server=\"" . $db2['server'] . "\"\n" . "dbg=0\n" . "[tables]\n" . "entries\t=\t\"entries\"")) { echo GOOD; } else { echo BAD; } fclose($fh); echo "<br><b>Installation done so far.</b><p>" . "Go to <a href='../'>homepage</a> to start."; /* _________________________ functions ______________________*/ echo "</body></html>";
public static function addPage($page, $imgs) { $mysql = new MySQL(); $data['pageid'] = $mysql->insert('page', $page); $pageid = $page['pageid']; foreach ($imgs as $img) { $imgObj['pageid'] = $pageid; $imgObj['img'] = $img; $mysql->insert('page_img', $imgObj); } $mysql->closeCon(); }
$max_count = count($the_tag); for ($n = 0; $n < $max_count; $n++) { $the_tag[$n] = trim($the_tag[$n], "_"); $the_tag[$n] = mysql_real_escape_string($the_tag[$n]); if (strlen($the_tag[$n]) < 3 || preg_match("/[\\d\\.]+/", $the_tag[$n])) { $db_tmp->update($setting['db']['pre_sub'] . "news_show", array("tag" => "replace('" . $the_tag[$n] . ",', '', tag)"), array("news_id", "n=", $record['news_id'])); $db_tmp->update($setting['db']['pre_sub'] . "news_show", array("tag" => "replace('," . $the_tag[$n] . "', '', tag)"), array("news_id", "n=", $record['news_id'])); continue; } if (strlen($the_tag[$n] > 50)) { $the_tag[$n] = substrPro($the_tag[$n], 0, 50); } if ($db_tmp->result($setting['db']['pre_sub'] . "news_tag", "id", array("tag", "=", $the_tag[$n]))) { $db_tmp->update($setting['db']['pre_sub'] . "news_tag", array("count" => "+1", "update_date" => "UNIX_TIMESTAMP()"), array("tag", "=", $the_tag[$n])); } else { $db_tmp->insert($setting['db']['pre_sub'] . "news_tag", array(0, $the_tag[$n], 1, 0, "UNIX_TIMESTAMP()", "UNIX_TIMESTAMP()")); } } if (++$n % 50 === 0) { $db_tmp->ReConnect(false, $setting['db']['name']); } } $db_tmp->delete($setting['db']['pre_sub'] . "news_tag", array(array("count", "n<", 2), array("click", "n<", 5, "and"), array("add_date", "f<", "UNIX_TIMESTAMP()-60*60*24*10", "and"))); $db->Free(); $n = 1; $db->select($setting['db']['pre_sub'] . "news_tag", "id, tag"); while ($record = $db->GetRS()) { $counter = $db_tmp->result($setting['db']['pre_sub'] . "news_show", "count(*)", array("tag", "like", $record['tag'])); $db_tmp->update($setting['db']['pre_sub'] . "news_tag", array("count" => $counter), array("id", "n=", $record['id'])); if (++$n % 50 === 0) { $db_tmp->ReConnect(false, $setting['db']['name']);
function cl_camara_division2array($division_id) { include "./db.inc.php"; $db = new MySQL(); //if(!$db->init()) die("¡¡¡ERROR!!!<BR>\n"); $url = "http://www.camara.cl/trabajamos/sala_votacion_detalle.aspx?prmID="; //3274 $out = array(); $out['division_id'] = $division_id; $html = Grabber($url . $division_id); $out['original_html'] = $html; $a_favor_sub = get_first_string($html, 'A favor</h2>', 'En contra</h2>'); $en_contra_sub = get_first_string($html, 'En contra</h2>', 'Abstención</h2>'); $abstencion_sub = get_first_string($html, 'Abstención</h2>', 'Dispensados Art. 5°</h2>'); $dispensados_sub = get_first_string($html, 'Dispensados Art. 5°</h2>', 'Pareos</h2>'); $pareos_sub = get_first_string($html, 'Pareos</h2>', '</div>'); $table_sub = get_first_string($html, '<table class="tabla resumenvotacion">', '</table>'); $table_control_number = returnSubstrings($table_sub, '<td>', '</td>'); $fecha = trim(get_first_string($html, 'Fecha:</strong>', '</p>')); $materia = str_replace("'", "\\'", trim(get_first_string($html, 'Materia:</strong>', '</p>'))); $out['info']['topic'] = $materia; if ($materia == "") { $materia = str_replace("'", "\\'", trim(get_first_string($html, 'Observaciones:</strong>', '</p>'))); $out['info']['topic'] = $materia; } $articulo = str_replace("'", "\\'", trim(get_first_string($html, 'Artículo:</strong>', '</p>'))); $out['info']['article'] = $articulo; $sesion = str_replace("'", "\\'", trim(get_first_string($html, 'Sesión:</strong>', '</p>'))); $out['info']['session'] = $sesion; $tramite = str_replace("'", "\\'", trim(get_first_string($html, 'Trámite:</strong>', '</p>'))); $out['info']['step'] = $tramite; $tipo_de_votacion = str_replace("'", "\\'", strtolower(trim(get_first_string($html, 'Tipo de votación:</strong>', '</p>')))); $out['info']['division_type'] = $tipo_de_votacion; $quorum = str_replace("'", "\\'", trim(get_first_string($html, 'Quorum:</strong>', '</p>'))); $out['info']['quorum'] = $quorum; $resultado = str_replace("'", "\\'", trim(get_first_string($html, 'Resultado:</strong>', '</p>'))); $out['info']['result'] = $resultado; $name_sub = trim(get_first_string($html, '<div id ="detail">', '<p>')); $name = trim(get_first_string($name_sub, '<h2>', '</h2>')); $out['info']['name'] = $name; $fecha_db_ar = explode(' ', $fecha); global $mes; $fecha_db = $fecha_db_ar[4] . '-' . $mes[trim($fecha_db_ar[2], '.')] . '-' . $fecha_db_ar[0] . ' ' . $fecha_db_ar[5]; $fecha_db_date = $fecha_db_ar[4] . '-' . $mes[trim($fecha_db_ar[2], '.')] . '-' . $fecha_db_ar[0]; $fecha_db_time = $fecha_db_ar[5]; $out['info']['date'] = $fecha_db_date; $out['info']['time'] = $fecha_db_time; /*$query = " INSERT INTO division (division_id,divided_on,name,materia,session,article,tramite,type,quorum,result) VALUES ($row, '$fecha_db', '$name', '$materia', '$sesion', '$articulo', '$tramite', '$tipo_de_votacion', '$quorum', '$resultado') ";*/ $camara = 'C.Diputados'; $en_sala = '1'; $out['info']['enSala'] = 'true'; if (strpos($name, 'Bolet') == 0) { $nro_boletin = substr($name, 12); } if ($nro_boletin != null) { $id_proyecto_ley = $db->getIdProyectoLey($nro_boletin); } else { $id_proyecto_ley = 0; } $id_sesion = $db->getIdSesion($sesion); $name = utf8_decode($name); $tipo_de_votacion = utf8_decode($tipo_de_votacion); $articulo = utf8_decode($articulo); $materia = utf8_decode($materia); $quorum = utf8_decode($quorum); $query = "INSERT INTO Votacion (name,camara,en_sala,tipo,articulo,materia,fecha,hora,voto_si,voto_no,voto_abs,voto_disp,voto_pareos,voto_aus,resultado,quorum,id_proyecto_ley,id_sesion,id_parlamento,created_at,updated_at) VALUES ('{$name}', '{$camara}', {$en_sala}, '{$tipo_de_votacion}', '{$articulo}', '{$materia}', '{$fecha_db_date}', '{$fecha_db_time}', {$table_control_number['0']}, {$table_control_number['1']}, {$table_control_number['2']}, {$table_control_number['3']}, 0, 0, '{$resultado}', '{$quorum}', {$id_proyecto_ley}, {$id_sesion}, {$division_id}, '" . date('Y-m-d H:m:s') . "', '" . date('Y-m-d H:m:s') . "')"; //echo $query; $id_votacion = $db->insert($query); //echo $id_votacion; $a_favor_ar = returnSubstrings($a_favor_sub, 'ID=', '">'); $en_contra_ar = returnSubstrings($en_contra_sub, 'ID=', '">'); $abstencion_ar = returnSubstrings($abstencion_sub, 'ID=', '">'); $dispensados_ar = returnSubstrings($dispensados_sub, 'ID=', '">'); $pareos_ar = returnSubstrings($pareos_sub, 'ID=', '">'); $out['total'] = array('yes' => 0, 'no' => 0, 'abstain' => 0, 'dispensed' => 0, 'paired' => 0); foreach ($a_favor_ar as $mp_row) { $db->insertVoto($id_votacion, $mp_row, 'y'); $name_pom = str_replace("'", "\\'", trim(get_first_string($a_favor_sub, 'prmID=' . $mp_row . '">', '</a>'))); $names[$name_pom][$mp_row] = $mp_row; $out['mp']['mp_' . $mp_row]['mp_id'] = $mp_row; $out['mp']['mp_' . $mp_row]['vote'] = 'y'; $name_pom2 = explode('.', $name_pom); $out['mp']['mp_' . $mp_row]['name'] = trim($name_pom2[1]) . '.' . $name_pom2[2]; if ($name_pom2[0] == 'Sra') { $out['mp']['mp_' . $mp_row]['sex'] = 'f'; } else { $out['mp']['mp_' . $mp_row]['sex'] = 'm'; } $out['total']['yes']++; } foreach ($en_contra_ar as $mp_row) { $db->insertVoto($id_votacion, $mp_row, 'n'); $name_pom = str_replace("'", "\\'", trim(get_first_string($en_contra_sub, 'prmID=' . $mp_row . '">', '</a>'))); $names[$name_pom][$mp_row] = $mp_row; $out['mp']['mp_' . $mp_row]['mp_id'] = $mp_row; $out['mp']['mp_' . $mp_row]['vote'] = 'n'; $name_pom2 = explode('.', $name_pom); $out['mp']['mp_' . $mp_row]['name'] = trim($name_pom2[1]) . '.' . $name_pom2[2]; if ($name_pom2[0] == 'Sra') { $out['mp']['mp_' . $mp_row]['sex'] = 'f'; } else { $out['mp']['mp_' . $mp_row]['sex'] = 'm'; } $out['total']['no']++; } foreach ($abstencion_ar as $mp_row) { $db->insertVoto($id_votacion, $mp_row, 'a'); $name_pom = str_replace("'", "\\'", trim(get_first_string($abstencion_sub, 'prmID=' . $mp_row . '">', '</a>'))); $names[$name_pom][$mp_row] = $mp_row; $out['mp']['mp_' . $mp_row]['mp_id'] = $mp_row; $out['mp']['mp_' . $mp_row]['vote'] = 'a'; $name_pom2 = explode('.', $name_pom); $out['mp']['mp_' . $mp_row]['name'] = trim($name_pom2[1]) . '.' . $name_pom2[2]; if ($name_pom2[0] == 'Sra') { $out['mp']['mp_' . $mp_row]['sex'] = 'f'; } else { $out['mp']['mp_' . $mp_row]['sex'] = 'm'; } $out['total']['abstain']++; } foreach ($dispensados_ar as $mp_row) { $db->insertVoto($id_votacion, $mp_row, 'd'); $name_pom = str_replace("'", "\\'", trim(get_first_string($dispensados_sub, 'prmID=' . $mp_row . '">', '</a>'))); $names[$name_pom][$mp_row] = $mp_row; $out['mp']['mp_' . $mp_row]['mp_id'] = $mp_row; $out['mp']['mp_' . $mp_row]['vote'] = 'd'; $name_pom2 = explode('.', $name_pom); $out['mp']['mp_' . $mp_row]['name'] = trim($name_pom2[1]) . '.' . $name_pom2[2]; if ($name_pom2[0] == 'Sra') { $out['mp']['mp_' . $mp_row]['sex'] = 'f'; } else { $out['mp']['mp_' . $mp_row]['sex'] = 'm'; } $out['total']['dispensed']++; } foreach ($pareos_ar as $mp_row) { $db->insertVoto($id_votacion, $mp_row, 'p'); $name_pom = str_replace("'", "\\'", trim(get_first_string($pareos_sub, 'prmID=' . $mp_row . '">', '</a>'))); $names[$name_pom][$mp_row] = $mp_row; $out['mp']['mp_' . $mp_row]['mp_id'] = $mp_row; $out['mp']['mp_' . $mp_row]['vote'] = 'p'; $name_pom2 = explode('.', $name_pom); $out['mp']['mp_' . $mp_row]['name'] = trim($name_pom2[1]) . '.' . $name_pom2[2]; if ($name_pom2[0] == 'Sra') { $out['mp']['mp_' . $mp_row]['sex'] = 'f'; } else { $out['mp']['mp_' . $mp_row]['sex'] = 'm'; } $out['total']['paired']++; //check if ($table_control_number[0] == $out['total']['yes'] and $table_control_number[1] == $out['total']['no'] and $table_control_number[2] == $out['total']['abstain'] and $table_control_number[3] == $out['total']['dispensed']) { } else { $out['error'] = 'wrong sums: yes:' . $table_control_number[0] . ' vs. ' . $out['total']['yes'] . ', no:' . $table_control_number[1] . ' vs. ' . $out['total']['no'] . ', abstain:' . $table_control_number[2] . ' vs. ' . $out['total']['abstain'] . ', dispensed:' . $table_control_number[3] . ' vs. ' . $out['total']['dispensed']; } } //updated Votacion con pareos y ausentes $ausentes = 120 - $table_control_number[0] - $table_control_number[1] - $table_control_number[2] - $out['total']['paired']; $db->updatePareosAusentes($id_votacion, $out['total']['paired'], $ausentes); if (strlen($html) < 8300) { $out['error'] = 'small file; might have not been downloaded correctly or wrong id'; } return $out; }