} elseif ($temp == 0) { echo 'Possible answer : (', implode(',', $part), ')', '/2 '; display_answer($rest); new_line(); } elseif (abs($temp) < $lowest_possible_result) { $lowest_possible_result = abs($temp); $alternative_answer = display_answer(array_merge(array_merge(array_merge(['('], $part), [')', '/2']), $rest), false, true); } } $temp = $sum_part * 2 + $sum_rest; if ($temp == $result) { echo '<strong>Answer : (', implode(',', $part), ')', 'x2 '; display_answer($rest); echo '</strong>'; break 3; } elseif ($temp == 0) { echo 'Possible answer : (', implode(',', $part), ')', 'x2 '; display_answer($rest); new_line(); } elseif (abs($temp) < $lowest_possible_result) { $lowest_possible_result = abs($temp); $alternative_answer = display_answer(array_merge(array_merge(array_merge(['('], $part), [')', 'x2']), $rest), false, true); } } } // end of METHOD #1 echo '<span style="color: red">No answer</span>'; } while (0); new_line(); echo 'Alternative answer : ', $alternative_answer; }
function import_db() { // Name of the file $filename = 'application/database/dump.sql'; Dotenv::load(__DIR__); // MySQL host $mysql_host = getenv('DB_HOST'); // MySQL username $mysql_username = getenv('DB_USERNAME'); // MySQL password $mysql_password = getenv('DB_PASSWORD'); // Database name $mysql_database = getenv('DB_DATABASE'); // Connect to MySQL server $connection = mysqli_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error()); // Select database if (!mysqli_select_db($connection, $mysql_database)) { die('Error selecting MySQL database: ' . mysql_error()); } // Temporary variable, used to store current query $templine = ''; // Read in entire file $lines = file($filename); // Loop through each line foreach ($lines as $line) { // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } // Add this line to the current segment $templine .= $line; // If it has a semicolon at the end, it's the end of the query if (substr(trim($line), -1, 1) == ';') { // Perform the query mysqli_query($connection, $templine) or print 'Error performing query \'<strong>' . $templine . '\': ' . mysqli_error() . '<br /><br />'; // Reset temp variable to empty $templine = ''; } } echo '<span class="success">Successfully Imported Database (<i class="fa fa-check-square-o"></i> PASS)</span>'; new_line(); }
function import_manifest($manifest_reg, $manifest_counter_result, $site_result, $site_has_cat_result, $delivery_result) { global $GME; echo "In import manifest"; connect_tablet(); //here we for the last time ask tavblet before connectin to root //check manifest unq number $GME .= new_line(" In import manifest "); // //extract manifest reg $id_manifest = $manifest_reg[0]; $manifest_unq_num = $manifest_reg[1]; $manifest_date = $manifest_reg[2]; $manifest_driver = $manifest_reg[3]; $manifest_closed = $manifest_reg[4]; //write a standard origin conversion function that //$manifest_siteid=$manifest_reg[5]; //converst tablet origin into dbs3 origin using post code as constanse $manifest_start_dbs = $manifest_reg[6]; //do it each time $manifest_end_dbs = $manifest_reg[7]; //site for site conversion //asssuming only one site $GME .= new_line(" Manifest array " . $manifest_reg[0] . " - " . $manifest_reg[1] . " - " . $manifest_reg[2] . " - " . $manifest_reg[3] . " - " . $manifest_reg[4] . " - " . $manifest_reg[5]); $site = mysql_fetch_array($site_result); $site_id = $site[0]; $site_origin_origin_id = $site[1]; //here a problem cince it may be with root system origin converted. Means that origins must be converted from tablet to root $site_ref_number = $site[2]; $site_rep_auth = $site[3]; $site_dest_location = $site[4]; $site_batch_date = $site[5]; $site_batch_id = $site[6]; $site_closed = $site[7]; ### //get post code from tablet $tablet_tmp_post_code = get_post_code($site_origin_origin_id); //get origin from tablet //checktabletpostcode echo "NEW CONV Ori:" . ($new_converted_origin = root_system_origin_from_post($tablet_tmp_post_code)); $GME .= new_line("NEW Conv ori:" . $new_converted_origin); $tablet_tmp_post_code = $new_converted_origin; /* $site_origin_tab=mysql_fetch_array($site_result); //get post code from tablet $tablet_tmp_post_code=get_post_code($site_origin_tab[1]); //get origin from tablet //checktabletpostcode echo "NEW CONV Ori:".$new_converted_origin= root_system_origin_post_code($tablet_tmp_post_code); */ //root_system_origin($origin_id); //check pos code root return origin id //Manifest reg id is taken from manifest, than is inserted into root system with conversion //we gona insert this to root system as AI. But we chcack manifest unq number //extract site -stage 2 /* $site_id=$site[0]; $site_origin_origin_id=$site[1]; $site_ref_number=$site[2]; $site_rep_auth=$site[3]; $site_dest_location=$site[4]; $site_batch_date=$site[5]; $site_batch_id=$site[6]; $site_closed=$site[7]; */ //variables for module conversion $stack_trace_manifest_reg_id; $stack_trace_manifest_reg_unq_number; $stack_trace_fresh_site_id; connect_dbs3(); //here we connect to main root system //check root system $sql = "SELECT * FROM manifest_reg WHERE manifest_unq_num='{$manifest_unq_num}'"; $result = query_select($sql); if ($num = mysql_num_rows($result) > 0) { return "manifest already exist in the system"; } /* //Checking if origins id is adjusted to coonversion module $conversion_post_code=get_post_code($site_origin_origin_id=$site[1]); //take tablet origin_id and compare to local echo $sql="SELECT origin_id FROM origin WHERE post_code='$conversion_post_code'"; $result=query_select($sql) or die(mysql_error()); $rek=mysql_fetch_array($result); $origin_in_root=$rek[0]; echo "NEW conversion id".$origin_in_root; */ connect_dbs3(); mysql_query("START TRANSACTION"); $flag = true; //here we insert as it goes manifest reg, but we need to keeptrace of it to update $manifest_siteid = 0; //we use blank one echo $query_manifest = "INSERT INTO manifest_reg(manifest_unq_num,date_manifest,driver_num,hash_serial,group1,closed,siteid,start_dbs,end_dbs) " . "VALUES ('{$manifest_unq_num}','{$manifest_date}','{$manifest_driver}','0','0','{$manifest_closed}','{$manifest_siteid}','{$manifest_start_dbs}','{$manifest_end_dbs}')"; $result = mysql_query($query_manifest) or trigger_error(mysql_error(), E_USER_ERROR); if (!$result) { $flag = false; } else { echo "Result manifest register done"; $GME .= new_line("Result manifest register done"); //if inserted correctly we take last insert id $stack_trace_manifest_reg_id = mysql_insert_id(); $stack_trace_manifest_reg_unq_number = $manifest_unq_num; } //manifest counter extract while ($manifest_counter = mysql_fetch_array($manifest_counter_result)) { echo "executing mysql counter"; //here we will be unsing manifest stack trace for manifest_reg echo $manifest_counter_id = $manifest_counter[0]; echo $manifest_counter_manifest_counter = $manifest_counter[1]; $manifest_counter_sub_cat = $manifest_counter[2]; $manifest_counter_manifest_sub_cat = $manifest_counter[3]; echo "reg:" . ($manifest_counter_manifest_reg_idmanifest_reg = $stack_trace_manifest_reg_id); //$manifest_counter[4]; deprecated $manifest_counter_finished = $manifest_counter[5]; echo $query_manifest_counter = "INSERT INTO manifest_counter(manifest_counter,sub_cat,manifest_sub_cat,manifest_reg_idmanifest_reg,finished) " . "VALUES ('{$manifest_counter_manifest_counter}','{$manifest_counter_sub_cat}','{$manifest_counter_manifest_sub_cat}','{$manifest_counter_manifest_reg_idmanifest_reg}','{$manifest_counter_finished}')"; $result = mysql_query($query_manifest_counter) or trigger_error(mysql_error(), E_USER_ERROR); if (!$result) { $flag = false; } else { echo "Result insert counter done"; //here we need a fresh site id not the old one from system. Its generated on level of adding site id } } echo "Done manifest counters successfult"; //IF FIRST STAGE DONE GO THROUGH SECOND ONE //SITE //asssuming only one site /* $site=mysql_fetch_array($site_result); $site_id=$site[0]; $site_origin_origin_id=$site[1]; //here a problem cince it may be with root system origin converted. Means that origins must be converted from tablet to root $site_ref_number=$site[2]; $site_rep_auth=$site[3]; $site_dest_location=$site[4]; $site_batch_date=$site[5]; $site_batch_id=$site[6]; $site_closed=$site[7]; */ $site_origin_origin_id = $tablet_tmp_post_code; //add one site echo $query_site = "INSERT INTO site(Origin_origin_id,site_ref_number,Rep_Auth,Dest_location,batch_date,batch_id,closed) " . "VALUES ('{$site_origin_origin_id}','{$site_ref_number}','{$site_rep_auth}','{$site_dest_location}','{$site_batch_date}','{$site_batch_id}','{$site_closed}')"; $result = mysql_query($query_site) or trigger_error(mysql_error(), E_USER_ERROR); if (!$result) { $flag = false; } else { echo "Done site"; echo $stack_trace_fresh_site_id = mysql_insert_id(); } //SITE HAS CATEGORY INSERT while ($site_has_cat = mysql_fetch_array($site_has_cat_result)) { $i++; $site_has_cat_id = $site_has_cat[0]; //$site_has_cat_site_site_id=$site_has_cat[1]; $site_has_cat_sub_cat_id = $site_has_cat[1]; $site_has_cat_quantity = $site_has_cat[3]; $site_has_cat_sum_weight = $site_has_cat[4]; $site_has_cat_site_site_id = $stack_trace_fresh_site_id; //$site_has_cat_sum_weight=0; //only adds few echo "</BR>" . $i; echo $query_site_has_cat = "INSERT INTO site_has_cat(Sub_cat_id_c,Site_site_id,Quantity,sum_weight) " . "VALUES ('{$site_has_cat_sub_cat_id}','{$site_has_cat_site_site_id}','{$site_has_cat_quantity}','{$site_has_cat_sum_weight}')"; $result = mysql_query($query_site_has_cat) or trigger_error(mysql_error(), E_USER_ERROR); if (!$result) { $flag = false; } else { echo "result site_has_cat Done"; } } //deliveries while ($delivery = mysql_fetch_array($delivery_result)) { $delivery_delivery_id = $delivery[0]; $delivery_trans_category = $delivery[1]; //$delivery_site_site_id=$delivery[2]; $delivery_date = $delivery[3]; $delivery_qtty_picked_up = $delivery[4]; $delivery_picker1 = $delivery[5]; $delivery_trans_ref_number = $delivery[6]; $delivery_closed = $delivery[7]; $delivery_qnum = $delivery[8]; $delivery_att_num = $delivery[9]; $delivery_site_site_id = $stack_trace_fresh_site_id; echo $query_delivery = "INSERT INTO delivery(Trans_Category_Category_id,Site_site_id,date,QtyPickedUp,picker1,trans_ref_num,closed,QNum,att_num)" . "VALUES ('{$delivery_trans_category}','{$delivery_site_site_id}','{$delivery_date}','{$delivery_qtty_picked_up}','{$delivery_picker1}','{$delivery_trans_ref_number}'," . "'{$delivery_closed}','{$delivery_qnum}','{$delivery_att_num}')"; $result = mysql_query($query_delivery) or trigger_error(mysql_error(), E_USER_ERROR); if (!$result) { $flag = false; } else { echo "result succesfully done deliveries"; } } //here we update site id in both manifest_reg and manifest_counter $update_manifest_reg = "UPDATE manifest_reg SET siteid='{$stack_trace_fresh_site_id}' WHERE idmanifest_reg='{$stack_trace_manifest_reg_id}'"; $result = query_select($update_manifest_reg); if (!$result) { $flag = false; } else { echo "result succesfully updated manifest reg siteid"; } if ($flag) { echo "Cimmited"; mysql_query("COMMIT"); } else { echo "Rolled backed"; mysql_query("ROLLBACK"); } //update manifest on table for cloas 1 if ($flag) { connect_tablet(); //the last one is to reove from tablet. make it unvisible $update_closed = "UPDATE manifest_reg SET closed=1 WHERE idmanifest_reg='{$id_manifest}'"; $rek = mysql_query($update_closed) or die(mysql_error()); } }
function run_checks($writable_files) { $passed = true; if (is_writable($writable_files)) { echo '<p>Files and Folders are Writable <i class="fa fa-check-circle-o"></i></p>'; $config_string = "<?php return array (\n 'db_host' => '',\n 'db_name' => '',\n 'db_user' => '',\n 'db_password' => '',\n);"; file_put_contents('./config.php', $config_string); } else { echo '<p>Files not writable! <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (version_compare(PHP_VERSION, "5.3.7", ">=")) { echo '<p>PHP 5.3.7 or greater installed <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>minumum version of PHP 5.4 is required <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (!ini_get('safe_mode')) { echo '<p>Safe mode is not enabled <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>Safe mode is enabled <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (defined('PDO::ATTR_DRIVER_NAME')) { echo '<p>PDO Driver is enabled <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>PDO Driver is not enabled <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (extension_loaded('mcrypt')) { echo '<p>Mcrypt library is available <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>Mcrypt library is not available <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (extension_loaded('gd')) { echo '<p>GD library is available <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>GD library is not available <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); if (function_exists('curl_init')) { echo '<p>Curl library is available <i class="fa fa-check-circle-o"></i></p>'; } else { echo '<p>Curl library is not available <i class="fa fa-times-circle-o"></i></p>'; $passed = false; } new_line(); return $passed; }