function __construct($dbms, $fn, $errno, $errmsg, $p1, $p2, $thisConnection) { $p1 = is_array($p1) ? recursive_implode($p1) : $p1; $p2 = is_array($p2) ? recursive_implode($p2) : $p2; switch ($fn) { case 'EXECUTE': $this->sql = $p1; $this->params = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}(\"{$p1}\")\n"; break; case 'PCONNECT': case 'CONNECT': $user = $thisConnection->user; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, '{$user}', '****', {$p2})\n"; break; default: $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, {$p2})\n"; break; } $this->dbms = $dbms; if ($thisConnection) { $this->host = $thisConnection->host; $this->database = $thisConnection->database; } $this->fn = $fn; $this->msg = $errmsg; if (!is_numeric($errno)) { $errno = -1; } parent::__construct($s, $errno); }
/** * Error Handler with PEAR support. This will be called with the following params * * @param $dbms the RDBMS you are connecting to * @param $fn the name of the calling function (in uppercase) * @param $errno the native error number from the database * @param $errmsg the native error msg from the database * @param $p1 $fn specific parameter - see below * @param $P2 $fn specific parameter - see below */ function ADODB_Error_PEAR($dbms, $fn, $errno, $errmsg, $p1 = false, $p2 = false) { global $ADODB_Last_PEAR_Error; if (error_reporting() == 0) { return; } // obey @ protocol $p1 = is_array($p1) ? recursive_implode($p1) : $p1; $p2 = is_array($p2) ? recursive_implode($p2) : $p2; switch ($fn) { case 'EXECUTE': $sql = $p1; $inputparams = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}(\"{$sql}\")"; break; case 'PCONNECT': case 'CONNECT': $host = $p1; $database = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}('{$host}', ?, ?, '{$database}')"; break; default: $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, {$p2})"; break; } $class = ADODB_PEAR_ERROR_CLASS; $ADODB_Last_PEAR_Error = new $class($s, $errno, $GLOBALS['_PEAR_default_error_mode'], $GLOBALS['_PEAR_default_error_options'], $errmsg); //print "<p>!$s</p>"; }
/** * Default Error Handler. This will be called with the following params * * @param $dbms the RDBMS you are connecting to * @param $fn the name of the calling function (in uppercase) * @param $errno the native error number from the database * @param $errmsg the native error msg from the database * @param $p1 $fn specific parameter - see below * @param $p2 $fn specific parameter - see below * @param $thisConn $current connection object - can be false if no connection object created */ function ADODB_Error_Handler($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection) { if (error_reporting() == 0) { return; } // obey @ protocol $p1 = is_array($p1) ? recursive_implode($p1) : $p1; $p2 = is_array($p2) ? recursive_implode($p2) : $p2; switch ($fn) { case 'EXECUTE': $sql = $p1; $inputparams = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}(\"{$sql}\")\n"; break; case 'PCONNECT': case 'CONNECT': $host = $p1; $database = $p2; $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$host}, '****', '****', {$database})\n"; break; default: $s = "{$dbms} error: [{$errno}: {$errmsg}] in {$fn}({$p1}, {$p2})\n"; break; } /* * Log connection error somewhere * 0 message is sent to PHP's system logger, using the Operating System's system * logging mechanism or a file, depending on what the error_log configuration * directive is set to. * 1 message is sent by email to the address in the destination parameter. * This is the only message type where the fourth parameter, extra_headers is used. * This message type uses the same internal function as mail() does. * 2 message is sent through the PHP debugging connection. * This option is only available if remote debugging has been enabled. * In this case, the destination parameter specifies the host name or IP address * and optionally, port number, of the socket receiving the debug information. * 3 message is appended to the file destination */ if (defined('ADODB_ERROR_LOG_TYPE')) { $t = date('Y-m-d H:i:s'); if (defined('ADODB_ERROR_LOG_DEST')) { error_log("({$t}) {$s}", ADODB_ERROR_LOG_TYPE, ADODB_ERROR_LOG_DEST); } else { error_log("({$t}) {$s}", ADODB_ERROR_LOG_TYPE); } } //print "<p>$s</p>"; trigger_error($s, ADODB_ERROR_HANDLER_TYPE); }
// get the highest marks for the current exam and store them in an array $highest_marks_[$current_exam][$k] = get_highest_mark($all_classmarks, $mark->subject, $exam->exam); // get the average marks for the current exam and store them in an array $average_marks_[$current_exam][$k] = get_average_mark($all_classmarks, $mark->subject, $exam->exam); // get the marks obtained for the current exam and store them in an array $marks_obtained_[$current_exam][$k] = get_marks_obtained($all_classmarks, $mark->subject, $exam->exam, $mark->studentID); $subjects_[$current_exam][$k] = $mark->subject; $k++; } } if (!empty($highest_marks_[$current_exam])) { //Convert array to list $highest_marks_list = implode(",", $highest_marks_[$current_exam]); $average_marks_list = implode(",", $average_marks_[$current_exam]); // Call recursive implode function...see heplers/action_helper.php $marks_obtained_list = recursive_implode($marks_obtained_[$current_exam]); //Flatten and process array return quoted string $list_of_subjects = $subjects_[$current_exam]; $subjects_list = process_subjects_array($list_of_subjects); $canvasID = "marks-chart-" . $exam->examID; echo $exam->exam; ?> <table class="table table-borderd"> <caption><h5>Mark Obtained Vs Average Marks Vs Highest Marks</h5></caption> <tr> <td> <div class="chart-container"> <canvas id="<?php
/** * Add item to the basket * * @param int $product_id * @param array $optionsArray * @param int $quantity * @return bool */ public function add($product_id, $optionsArray = null, $quantity = 1) { foreach ($GLOBALS['hooks']->load('class.cart.add.pre') as $hook) { include $hook; } // Prevent quantities of less than one or non numerical user input if (!is_numeric($quantity) || $quantity < 1) { $quantity = 1; } // Don't allow products to be added to the basket if prices are hidden AND they're not logged in if ($GLOBALS['session']->get('hide_prices')) { if (isset($_GET['_g']) && $_GET['_g'] == 'ajaxadd') { $path = $GLOBALS['seo']->buildURL('prod', $_POST['add']); $GLOBALS['debug']->supress(); die('Redir:' . $path); } else { httpredir(currentPage()); } } // Handle gift certs $gc = $GLOBALS['config']->get('gift_certs'); if (isset($gc['product_code']) && $product_id == $gc['product_code'] && !empty($optionsArray)) { $hash = md5(recursive_implode('{@}', $optionsArray)); if (isset($this->basket['contents'][$hash])) { // Increment quantity $this->basket['contents'][$hash]['quantity'] += $quantity; $product = $GLOBALS['catalogue']->getProductData($this->basket['contents'][$hash]['id']); $this->basket['contents'][$hash]['total_price_each'] = $product['price'] + $this->basket['contents'][$hash]['option_line_price']; } else { // Add to basket $this->basket['contents'][$hash] = array('id' => $product_id, 'quantity' => $quantity, 'digital' => $optionsArray['method'] == 'e' ? true : false, 'certificate' => array('value' => $optionsArray['value'], 'name' => $optionsArray['name'], 'email' => $optionsArray['email'], 'message' => $optionsArray['message'])); } $this->save(); httpredir($GLOBALS['config']->get('config', 'basket_jump_to') ? $GLOBALS['rootRel'] . 'index.php?_a=basket' : currentPage(null)); return true; } else { if (!is_null($product_id) && is_numeric($product_id)) { $proceed = true; $options_identifier_string = $GLOBALS['catalogue']->defineOptionsIdentifier($optionsArray); $product = $GLOBALS['catalogue']->getProductData($product_id, 1, false, 10, 1, false, $options_identifier_string); if ($product) { // Check for options $options = $GLOBALS['catalogue']->getProductOptions($product_id); if ($GLOBALS['catalogue']->getOptionRequired() && ($options && empty($optionsArray))) { // Options needed - Redirect to product page // Set GUI_MESSAGE error, then redirect $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_option_required']); $this->redirectToProductPage($product_id); return true; } else { // Check required options have a value! $quantity = is_numeric($quantity) && $quantity > 0 ? $quantity : 1; $stock_level = $GLOBALS['catalogue']->getProductStock($product['product_id'], $options_identifier_string); // Check stock level if ($product['use_stock_level'] && !$GLOBALS['config']->get('config', 'basket_out_of_stock_purchase')) { if ($stock_level <= 0) { $max_stock = 0; } else { $max_stock = $stock_level; } } if (isset($max_stock) && $max_stock <= 0) { if (is_array($optionsArray)) { $stock_note = $GLOBALS['session']->has('restock_note') ? $GLOBALS['session']->get('restock_note') : ''; $GLOBALS['session']->delete('restock_note'); $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_no_stock_available_options'] . ' ' . $stock_note); } else { $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_no_stock_available']); } $this->redirectToProductPage($product_id); return false; } $this->checkMinimumProductQuantity($product_id, $quantity, true); // Add item to basket $hash = md5($product['product_id'] . (!empty($optionsArray) ? $product['name'] . recursive_implode('{@}', $optionsArray) : $product['name'])); if (isset($this->basket['contents'][$hash])) { // Update quantity if (isset($max_stock)) { $current = $this->basket['contents'][$hash]['quantity']; $request = $current + $quantity; if ($request > $max_stock) { $GLOBALS['gui']->setError($GLOBALS['language']->checkout['error_too_many_added']); $quantity = $max_stock - $current; $stock_warning = true; } } $this->basket['contents'][$hash]['quantity'] += $quantity; } else { // Add to basket if (isset($max_stock) && $quantity > $max_stock) { $GLOBALS['gui']->setError($GLOBALS['language']->checkout['error_too_many_added']); $quantity = $max_stock; $stock_warning = true; } $this->basket['contents'][$hash] = array('id' => $product_id, 'quantity' => $quantity, 'digital' => $product['digital']); if ($options && !empty($optionsArray)) { // Add options to the basket item foreach ($optionsArray as $option_id => $option_value) { $required = $GLOBALS['db']->select('CubeCart_option_group', array('option_required', 'option_type'), array('option_id' => (int) $option_id)); $require = $required ? (bool) $required[0]['option_required'] : false; $add_option = true; if (is_array($option_value)) { foreach (array_values($option_value) as $value) { if ($add_option && !$this->_checkOption($value, $require)) { $add_option = false; $proceed = false; } else { if (empty($option_value)) { $add_option = false; } else { $imploded = implode('', $option_value); if (empty($imploded)) { $add_option = false; } } } } } else { if ($add_option && !$this->_checkOption($option_value, $require)) { $add_option = false; $proceed = false; } else { if (empty($option_value) && !is_numeric($option_value)) { $add_option = false; } } } if ($add_option) { $this->basket['contents'][$hash]['options'][$option_id] = $option_value; } else { if (!$proceed) { // Product can't be added without required option unset($this->basket['contents'][$hash]); break; } } } $this->basket['contents'][$hash]['options_identifier'] = $options_identifier_string; if (!$proceed) { // No required options selected if (isset($_GET['_g']) && $_GET['_g'] == 'ajaxadd') { $GLOBALS['gui']->setError($GLOBALS['language']->catalogue['error_option_required']); $this->redirectToProductPage($product_id); } else { httpredir(currentPage(null, array('error' => 'option'))); } return false; } } } foreach ($GLOBALS['hooks']->load('class.cart.add.save') as $hook) { include $hook; } //Save before the jump $this->save(); foreach ($GLOBALS['hooks']->load('class.cart.add.preredirect') as $hook) { include $hook; } // Jump to basket, or return to product page? $jumpto = $GLOBALS['config']->get('config', 'basket_jump_to') ? $GLOBALS['rootRel'] . 'index.php?_a=basket' : currentPage(null); if (isset($_GET['_g']) && $_GET['_g'] == 'ajaxadd' && $GLOBALS['config']->get('config', 'basket_jump_to')) { $GLOBALS['debug']->supress(); die($GLOBALS['seo']->rewriteUrls("Redir:" . $jumpto, true)); } elseif (isset($_GET['_g']) && $_GET['_g'] == 'ajaxadd') { $GLOBALS['debug']->supress(); if ($stock_warning) { die('Redir:' . $GLOBALS['rootRel'] . 'index.php?_a=basket'); } } else { httpredir($jumpto); } return true; } } } } return false; }
/** * Recursive implode array * kromped at yahoo dot com @ php.net * * @param string $glue * @param array $pieces * @return string */ function recursive_implode($glue, $pieces) { if (is_array($pieces)) { foreach ($pieces as $r_pieces) { if (is_array($r_pieces)) { $ret[] = recursive_implode($glue, $r_pieces); } else { $ret[] = $r_pieces; } } return implode($glue, $ret); } return is_scalar($pieces) ? (string) $pieces : false; }
$queryFlag = true; } if ($request["typeOfSpecies"]) { $varTypeOfSpecies = $request["typeOfSpecies"]; $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $TypeOfSpeciesSQLQuery = $conn->prepare("SELECT SP.SpeciesID FROM dvem_v01.speciesmaster as SP where SP.speciesName IN ({$varTypeOfSpecies}) "); $TypeOfSpeciesSQLQuery->execute(); $varTypeOfSpeciesResult = recursive_implode($TypeOfSpeciesSQLQuery->fetchAll(PDO::FETCH_ASSOC)); $queryFlag = true; } if ($request["typeOfSpeciality"]) { $varTypeOfSpeciality = $request["typeOfSpeciality"]; $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $TypeOfSpecialitySQLQuery = $conn->prepare("SELECT SM.SpecialityID FROM dvem_v01.specialitymaster as SM where SM.SpecialityName IN ({$varTypeOfSpeciality}) "); $TypeOfSpecialitySQLQuery->execute(); $varTypeOfSpecialityResult = recursive_implode($TypeOfSpecialitySQLQuery->fetchAll(PDO::FETCH_ASSOC)); $queryFlag = true; } if ($queryFlag) { // Now that we know what options have been passed from the search query, lets use them to create a sql statement: $sql = "select id, PrimaryAuthors as primary_authors, PrimaryTitle as primary_title, PubYear as pub_year from primarystudiesheader as PH where "; if ($typeOfStudyResult) { $sql = $sql . "PH.StudyTypeMasterID IN ('" . $typeOfStudyResult . "')"; } if ($varTypeOfSpeciesResult) { $sql = $sql . " AND "; $sql = $sql . "PH.SpeciesMasterID IN ('" . $varTypeOfSpeciesResult . "')"; } if ($varTypeOfSpecialityResult) { $sql = $sql . " AND "; $sql = $sql . "PH.SpecialityHeaderID IN ( select SH.specialityheaderid from specialityheader as SH JOIN specialitylines as SL\n where SH.specialityheaderid = SL.specialityheaderid && SL.SpecialityMasterID\n IN ( '" . $varTypeOfSpecialityResult . "')) group by SH.specialityheaderid)";
function create_sql_exception_message($e, $sql, $values) { $message = 'Failed to get a recordset: ' . $e->getMessage() . "Command was: {$sql}"; if (is_array($values) && count($values) > 0) { $message .= ' and values was (' . recursive_implode($values, true) . ')'; } return $message; }