function insert_item($dbc, $values, $status) { if ($status == 'lost') { $person = 'owner'; } else { $person = 'finder'; } # Get the next id for the stuff table $id = get_next_id($dbc); foreach ($values as $key => $value) { # Sanitize the input $values[$key] = mysqli_real_escape_string($dbc, $value); } # Get the location id by name $building = mysqli_real_escape_string($dbc, $id); $location_id = get_location_id($dbc, $values['building']); $person_value = $values[$person]; $valueString = "({$id}, '{$values['item']}', '{$person_value}', '{$values['phone']}', '{$values['email']}', {$location_id}, '{$values['room']}', '{$values['description']}', NOW(), NOW(), '{$status}')"; $query = "INSERT INTO stuff(id, item, {$person}, phone, email, location_id, room, description, create_date, update_date, status) VALUES " . $valueString; $results = mysqli_query($dbc, $query); check_results($dbc, $results); #mysqli_free_result($results) if (!$results) { return false; } else { # If succesfful, return the id of the newly inserted item return $id; } }
/** * combine BatchOuts from Threads * * @param int order_id * @return int count of CheckOuts combined */ function JKY_combine_batchouts($the_ids) { $db = Zend_Registry::get('db'); $my_id = get_next_id('BatchOuts'); $sql = 'INSERT INTO BatchOuts ' . 'SELECT ' . $my_id . ' , ' . get_session('user_id') . ' , NOW()' . ' , status' . ' , MIN(checkout_id)' . ' , thread_id' . ' , batchin_id' . ' , req_line_id' . ' , tdyer_thread_id' . ' , order_thread_id' . ' , code' . ' , batch' . ' , AVG(unit_price)' . ' , SUM(requested_weight)' . ' , AVG(average_weight)' . ' , SUM(requested_boxes)' . ' , SUM(reserved_boxes)' . ' , SUM(checkout_boxes)' . ' , SUM(checkout_weight)' . ' FROM BatchOuts' . ' WHERE id IN (' . $the_ids . ')'; log_sql('BatchOuts', $my_id, $sql); $db->query($sql); insert_changes($db, 'BatchOuts', $my_id); $sql = 'SELECT *' . ' FROM BatchOuts' . ' WHERE id IN (' . $the_ids . ')'; log_sql('BatchOuts', $my_id, $sql); /* $sql= 'UPDATE BatchOuts ' . ' SET status = "History"' . ' FROM BatchOuts' . ' WHERE id IN (' . $the_ids . ')' ; */ $my_rows = $db->fetchAll($sql); foreach ($my_rows as $my_row) { $sql = 'UPDATE BatchOuts' . ' SET status = "History"' . ' WHERE id = ' . $my_row['id']; log_sql('BatchOuts', $my_row['id'], $sql); $db->query($sql); insert_changes($db, 'BatchOuts', $my_row['id']); } return $my_id; }
/** * generate Purchase * * @param int purchase_id * @return int count of Incomings generated */ function JKY_generate_purchase($the_id) { $db = Zend_Registry::get('db'); $sql = 'SELECT *' . ' FROM Purchases' . ' WHERE id = ' . $the_id; $my_purchase = $db->fetchRow($sql); $sql = 'SELECT *' . ' FROM PurchaseLines' . ' WHERE parent_id = ' . $the_id; $my_rows = $db->fetchAll($sql); $my_count = 0; foreach ($my_rows as $my_row) { $my_incoming_id = get_next_id('Incomings'); $sql = 'INSERT Incomings' . ' SET id = ' . $my_incoming_id . ', updated_by = ' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', incoming_number = ' . $my_incoming_id . ', supplier_id = ' . $my_purchase['supplier_id'] . ', invoice_date ="' . $my_row['expected_date'] . '"' . ', invoice_weight = ' . $my_row['expected_weight']; log_sql('Incomings', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'Incomings', $my_incoming_id); $my_batchin_id = get_next_id('Batches'); $sql = 'INSERT Batches' . ' SET id = ' . $my_batchin_id . ', updated_by = ' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', incoming_id = ' . $my_incoming_id . ', thread_id = ' . $my_row['thread_id'] . ', purchase_line_id = ' . $my_row['id']; log_sql('Batches', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'Batches', $my_batchin_id); $sql = 'UPDATE PurchaseLines' . ' SET batch_id = ' . $my_batchin_id . ' WHERE id = ' . $my_row['id']; log_sql('PurchaseLines', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'PurchaseLines', $my_row['id']); $my_count++; } $sql = 'UPDATE Purchases' . ' SET status = "Active"' . ' WHERE id = ' . $the_id; log_sql('Purchases', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'Purchases', $the_id); return $my_count; }
/** * Create a mutex for enforcing mutual exclusion * * @param string $name the system wide name of the mutex * @param boolane $acquire whether or not to acquire the mutex after it is created * @return Mutex */ function Mutex($name, $acquire = false) { global $DBCONN, $TBLPREFIX; if (!Mutex::checkDBCONN()) { return false; } $this->name = $name; //-- check if this mutex already exists $sql = "SELECT 1 FROM {$TBLPREFIX}mutex WHERE mx_name='" . $DBCONN->escapeSimple($name) . "'"; $res = dbquery($sql); if (DB::isError($res)) { return false; } $num_rows = $res->numRows(); $res->free(); //-- mutex doesn't exist so create it if ($num_rows == 0) { $sql = "INSERT INTO {$TBLPREFIX}mutex (mx_id, mx_name, mx_thread) VALUES (" . get_next_id("mutex", "mx_id") . ", '" . $DBCONN->escapeSimple($this->name) . "', '0')"; $res = dbquery($sql); } $this->waitCount = 0; if ($acquire) { $this->Wait(); } }
/** * generate Order from OSAs * * @param int quotation_id * @return int count of Orders generated */ function JKY_generate_order($the_id) { $db = Zend_Registry::get('db'); $sql = 'SELECT *' . ' FROM OSAs' . ' WHERE id = ' . $the_id; $my_osa = $db->fetchRow($sql); $sql = 'SELECT *' . ' FROM OSA_Lines' . ' WHERE parent_id = ' . $the_id; $my_rows = $db->fetchAll($sql); $my_count = 0; foreach ($my_rows as $my_row) { $my_osa_line_id = $my_row['id']; $sql = 'SELECT *' . ' FROM OSA_Colors' . ' WHERE parent_id = ' . $my_osa_line_id; $my_colors = $db->fetchAll($sql); foreach ($my_colors as $my_color) { $my_order_id = get_next_id('Orders'); $sql = 'INSERT Orders' . ' SET id =' . $my_order_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', order_number =' . $my_order_id . ', osa_line_id =' . $my_osa_line_id . ', osa_number =' . $my_osa['osa_number'] . ', ordered_at ="' . $my_osa['ordered_at'] . '"' . ', needed_at ="' . $my_osa['needed_at'] . '"' . ', quoted_units =' . $my_row['units'] . ', quoted_pieces =' . $my_color['quoted_pieces'] . ', quoted_weight =' . $my_color['quoted_weight'] . ', ordered_pieces =' . $my_color['ordered_pieces'] . ', ordered_weight =' . $my_color['ordered_weight']; if ($my_osa['customer_id']) { $sql .= ', customer_id=' . $my_osa['customer_id']; } if ($my_row['product_id']) { $sql .= ', product_id=' . $my_row['product_id']; } if ($my_color['color_id']) { $sql .= ', color_id=' . $my_color['color_id']; } if ($my_color['ftp_id']) { $sql .= ', ftp_id=' . $my_color['ftp_id']; } if ($my_color['machine_id']) { $sql .= ', machine_id=' . $my_color['machine_id']; } if ($my_color['partner_id']) { $sql .= ', partner_id=' . $my_color['partner_id']; } log_sql('Orders', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'Orders', $my_order_id); /* $sql= 'UPDATE OSA_lines' . ' SET status = "Active"' . ' WHERE id = ' . $my_row['id'] ; log_sql('OSA_Lines', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'OSA_Lines', $my_row['id']); */ $my_count++; } } $sql = 'UPDATE OSAs' . ' SET status = "Active"' . ' WHERE id = ' . $the_id; log_sql('OSAs', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'OSAs', $the_id); return $my_count; }
/** * generate CheckOut from Planning Orders * * @param int order_id * @return int count of CheckOuts generated */ function JKY_generate_checkout($the_id) { $db = Zend_Registry::get('db'); $sql = 'SELECT *' . ' FROM Orders' . ' WHERE id = ' . $the_id; $my_order = $db->fetchRow($sql); $sql = 'SELECT *' . ' FROM OrdThreads' . ' WHERE parent_id = ' . $the_id; $my_rows = $db->fetchAll($sql); /* $my_needed_at = $my_order['needed_at']; if ($my_needed_at == null) { $my_needed_at = get_time(); } */ $my_checkout_id = get_next_id('CheckOuts'); $sql = 'INSERT CheckOuts' . ' SET id =' . $my_checkout_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', number =' . $my_checkout_id . ', requested_at ="' . get_time() . '"' . ', requested_weight =' . $my_order['ordered_weight']; if ($my_order['machine_id']) { $sql .= ', machine_id=' . $my_order['machine_id']; } if ($my_order['partner_id']) { $sql .= ', partner_id=' . $my_order['partner_id']; } log_sql('CheckOuts', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'CheckOuts', $my_checkout_id); $my_count = 0; foreach ($my_rows as $my_row) { $my_ord_thread_id = $my_row['id']; $my_batch = db_get_row('Batches', 'id=' . $my_row['batchin_id']); $my_ordered_weight = $my_row['ordered_weight']; $my_ordered_boxes = ceil((double) $my_ordered_weight / (double) $my_batch['average_weight']); $my_batchout_id = get_next_id('BatchOuts'); $sql = 'INSERT BatchOuts' . ' SET id =' . $my_batchout_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', checkout_id =' . $my_checkout_id . ', thread_id =' . $my_row['thread_id'] . ', batchin_id =' . $my_row['batchin_id'] . ', order_thread_id =' . $my_ord_thread_id . ', batch ="' . $my_batch['batch'] . '"' . ', unit_price =' . $my_batch['unit_price'] . ', average_weight =' . $my_batch['average_weight'] . ', requested_weight =' . $my_ordered_weight . ', requested_boxes =' . $my_ordered_boxes; log_sql('BatchOuts', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'BatchOuts', $my_batchout_id); $sql = 'UPDATE OrdThreads' . ' SET batchout_id = ' . $my_batchout_id . ' WHERE id = ' . $my_ord_thread_id; log_sql('OrdThreads', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'OrdThreads', $my_ord_thread_id); $my_count++; } $sql = 'UPDATE Orders' . ' SET status = "Active"' . ' WHERE id = ' . $the_id; log_sql('Orders', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'Orders', $the_id); return $my_count; }
$url = 'http://' . $url; } $error = process_url($url); if ($error > 0) { goto out; } $url = trim($url, '/'); $codes = get_codes_for_url($url); $ip = get_IP(); $uuid = DEFAULT_UUID; if (strlen($code) == 0) { if (count($codes) == 0) { $id = get_next_id(); $code = int2code($id, false); if (code_spam_exists($code)) { $id = mt_rand(get_next_id() + 1, 0xffffff); $code = int2code($id, false); } insert_url($code, $url, $ip, $uuid); } else { $code = $codes[0]->code; } } else { if (!empty($codes)) { if (in_array($code, $codes)) { goto out; } } if (code_exists($code)) { $error = ERR_ALIAS_ALREADY_EXISTS; goto out;
private function history_log($method, $table, $parent_id, $new, $old) { $history = ''; $first = ''; foreach ($new as $key => $value) { if ($method == 'update') { if ($key != 'updated_at' and $new[$key] != $old[$key]) { $history .= $first . $key . ':' . $old[$key] . '=>' . $value; $first = ', '; } } else { $history .= $first . $key . ':' . $value; $first = ', '; } } if (empty($history)) { return; } $my_id = get_next_id('History'); $sql = 'INSERT History' . ' SET id=' . $my_id . ', updated_by=' . get_session('user_id') . ', updated_at="' . get_time() . '"' . ', parent_name="' . $table . '"' . ', parent_id=' . $parent_id . ', method="' . $method . '"' . ', history="' . $history . '"'; //$this->log_sql('History', $my_id, $sql); $db = Zend_Registry::get('db'); $db->query($sql); insert_changes($db, 'History', $my_id); }
/** * Adds a news item to the database * * This function adds a news item represented by the $news array to the database. * If the $news array has an ["id"] field then the function assumes that it is * as update of an older news item. * * @author John Finlay * @param array $news a news item array */ function addNews($news) { global $TBLPREFIX; if (!isset($news["date"])) { $news["date"] = client_time(); } if (!empty($news["id"])) { // In case news items are added from usermigrate, it will also contain an ID. // So we check first if the ID exists in the database. If not, insert instead of update. $exists = PGV_DB::prepare("SELECT 1 FROM {$TBLPREFIX}news where n_id=?")->execute(array($news["id"]))->fetchOne(); if (!$exists) { return (bool) PGV_DB::prepare("INSERT INTO {$TBLPREFIX}news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")->execute(array($news["id"], $news["username"], $news["date"], $news["title"], $news["text"])); } else { return (bool) PGV_DB::prepare("UPDATE {$TBLPREFIX}news SET n_date=?, n_title=? , n_text=? WHERE n_id=?")->execute(array($news["date"], $news["title"], $news["text"], $news["id"])); } } else { return (bool) PGV_DB::prepare("INSERT INTO {$TBLPREFIX}news (n_id, n_username, n_date, n_title, n_text) VALUES (?, ? ,? ,? ,?)")->execute(array(get_next_id("news", "n_id"), $news["username"], $news["date"], $news["title"], $news["text"])); } }
//插入ec_crmentity $insertcrmentityordersql = "insert into ec_crmentity(crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) " . "values(" . $salesorderid . "," . $current_user->id . "," . $current_user->id . ",'SalesOrder','" . $description_order . "','" . $createdtime_order . "','" . $modifiedtime_order . "')"; $adb->query($insertcrmentityordersql); //商品数字id $num_iid = $order['num_iid']; //判断产品是否已存在 $productid_tmp = checkItemIsExist($num_iid); if (empty($productid_tmp)) { //获取订单产品信息 $ItemInfo = getProductInfo($rooturl, $session, $appKey, $appSecret, $num_iid); if (empty($ItemInfo)) { $errormess .= "获取订单产品信息失败。<br>"; } else { $productid = $adb->getUniqueID("ec_crmentity"); $productname = $ItemInfo['title']; $productcode = $product_seqprefix . get_next_id('ec_products'); //商品url $detail_url = $ItemInfo['detail_url']; //商品数量 $pro_num = $ItemInfo['num']; //商品价格 $price = $ItemInfo['price']; $comment = $sku_properties_name; //创建时间 $createdtime_pro = $ItemInfo['created']; if ($createdtime_pro == '') { $createdtime_pro = date("Y-m-d H:i:s"); } //修改时间 $modifiedtime_pro = $ItemInfo['modified']; if ($modifiedtime_pro == '') {
case 'delete': PGV_DB::prepare("DELETE FROM {$TBLPREFIX}blocks WHERE b_order=? AND b_name=? AND b_username=?")->execute(array($id, 'faq', $oldGEDCOM)); AddToChangeLog("FAQ item has been deleted.<br />Header ID: " . $pidh . ".<br />Body ID: " . $pidb, $oldGEDCOM); break; case 'add': $faqs = get_faq_data(); if (isset($faqs[$order])) { // New position number is already in use: find next higher one that isn't used while (true) { $order++; if (!isset($faqs[$order])) { break; } } } $newid = get_next_id("blocks", "b_id"); $header = str_replace(array('<', '>'), array('<', '>'), $header); PGV_DB::prepare("INSERT INTO {$TBLPREFIX}blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)")->execute(array($newid, $whichGEDCOM, 'header', $order, 'faq', serialize($header))); $body = str_replace(array('<', '>'), array('<', '>'), $body); PGV_DB::prepare("INSERT INTO {$TBLPREFIX}blocks (b_id, b_username, b_location, b_order, b_name, b_config) VALUES (?, ?, ?, ?, ?, ?)")->execute(array($newid + 1, $whichGEDCOM, 'body', $order, 'faq', serialize($body))); AddToChangeLog("FAQ item has been added.<br />Header ID: " . $newid . ".<br />Body ID: " . ($newid + 1), $whichGEDCOM); break; case 'moveup': $faqs = get_faq_data(); if (isset($faqs[$id - 1])) { PGV_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")->execute(array($id, $faqs[$id - 1]["header"]["pid"], 'header')); PGV_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")->execute(array($id, $faqs[$id - 1]["body"]["pid"], 'body')); } PGV_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")->execute(array($id - 1, $pidh, 'header')); PGV_DB::prepare("UPDATE {$TBLPREFIX}blocks SET b_order=? WHERE b_id=? and b_location=?")->execute(array($id - 1, $pidb, 'body')); AddToChangeLog("FAQ item has been moved up.<br />Header ID: " . $pidh . ".<br />Body ID: " . $pidb, $oldGEDCOM);
function user_picture($picture_id, $user_id = NULL, $album_id = NULL) { $this->data['page_title'] = "User Album"; $the_row = $this->m_custom->getOneUserPicture($picture_id); if ($the_row) { $message_info = ''; if ($this->ion_auth->logged_in()) { $login_id = $this->ion_auth->user()->row()->id; //$login_data = $this->m_custom->getUser($login_id); } $user_row = $this->m_custom->getUserInfo($the_row['user_id']); $this->data['picture_id'] = $picture_id; $this->data['picture_user_id'] = $the_row['user_id']; $this->data['user_name_url'] = $this->m_custom->generate_user_link($the_row['user_id']); $this->data['user_name'] = $this->m_custom->display_users($the_row['user_id']); $this->data['title'] = $the_row['title']; $this->data['description'] = $the_row['description']; $this->data['image_url'] = base_url($this->album_user . $the_row['image']); $this->data['like_url'] = $this->m_custom->generate_like_link($picture_id, 'usa'); $this->data['comment_url'] = $this->m_custom->generate_comment_link($picture_id, 'usa'); $this->data['average_rating'] = $this->m_custom->activity_rating_average($picture_id, 'usa'); $this->data['message'] = $this->session->flashdata('message'); $this->data['item_id'] = array('type' => 'hidden', 'name' => 'item_id', 'id' => 'item_id', 'value' => $picture_id); $this->data['item_type'] = array('type' => 'hidden', 'name' => 'item_type', 'id' => 'item_type', 'value' => 'usa'); if (check_correct_login_type($this->group_id_user)) { $this->data['radio_level'] = " "; } else { $this->data['radio_level'] = "disabled"; } $this->data['page_path_name'] = 'all/picture_user'; if ($user_id != NULL) { $current_list = $this->m_custom->getAlbumUser($user_id, $album_id); $id_array = get_key_array_from_list_array($current_list, 'user_album_id'); $previous_id = get_previous_id($picture_id, $id_array); $next_id = get_next_id($picture_id, $id_array); if ($previous_id) { $this->data['previous_url'] = base_url() . "all/user_picture/" . $previous_id . "/" . $user_id . "/" . $album_id; } if ($next_id) { $this->data['next_url'] = base_url() . "all/user_picture/" . $next_id . "/" . $user_id . "/" . $album_id; } } $meta = array(array('property' => 'og:type', 'content' => 'article'), array('property' => 'og:title', 'content' => $user_row['name']), array('property' => 'og:description', 'content' => limit_character($the_row['description'], 150)), array('property' => 'og:image', 'content' => base_url($this->album_user . $the_row['image']))); $this->data['meta_fb'] = meta_fb($meta); $this->data['page_path_name'] = 'all/picture_user'; $this->load->view('template/index_background_blank', $this->data); } else { redirect('/', 'refresh'); } }
/** * import media items from record * @todo Decide whether or not to update the original gedcom file * @return string an updated record */ function update_media($gid, $gedrec, $update = false) { global $GEDCOMS, $FILE, $TBLPREFIX, $media_count, $found_ids; global $zero_level_media, $fpnewged, $MAX_IDS, $keepmedia, $gBitDb; if (!isset($media_count)) { $media_count = 0; } if (!isset($found_ids)) { $found_ids = array(); } if (!isset($zero_level_media)) { $zero_level_media = false; } if (!$update && !isset($MAX_IDS["OBJE"])) { if (!$keepmedia) { $MAX_IDS["OBJE"] = 1; } else { $MAX_IDS["OBJE"] = $gBitDb->getOne("SELECT ni_id FROM {$TBLPREFIX}nextid WHERE ni_type=? AND ni_gedfile=?", array('OBJE', $GEDCOMS[$FILE]['id'])); } } //-- handle level 0 media OBJE seperately $ct = preg_match("/0 @(.*)@ OBJE/", $gedrec, $match); if ($ct > 0) { $old_m_media = $match[1]; $m_id = get_next_id("media", "m_id"); /** * Hiding some code in order to fix a very annoying bug * [ 1579889 ] Upgrading breaks Media links * * Don't understand the logic of renumbering media objects ?? * if ($update) { $new_m_media = $old_m_media; } else { if (isset ($found_ids[$old_m_media])) { $new_m_media = $found_ids[$old_m_media]["new_id"]; } else { $new_m_media = get_new_xref("OBJE"); $found_ids[$old_m_media]["old_id"] = $old_m_media; $found_ids[$old_m_media]["new_id"] = $new_m_media; } } **/ $new_m_media = $old_m_media; //print "RECORD: old $old_m_media new $new_m_media<br />"; $gedrec = preg_replace("/@" . $old_m_media . "@/", "@" . $new_m_media . "@", $gedrec); $media = new Media($gedrec); //--check if we already have a similar object $new_media = Media::in_obje_list($media); if (!$new_media) { $gBitDb->query("INSERT INTO {$TBLPREFIX}media (m_id, m_media, m_ext, m_titl, m_file, m_gedfile, m_gedrec) VALUES (?, ?, ?, ?, ?, ?, ?)", array($m_id, $new_m_media, $media->ext, $media->title, $media->file, $GEDCOMS[$FILE]["id"], $gedrec)); $media_count++; } else { $new_m_media = $new_media; $found_ids[$old_m_media]["old_id"] = $old_m_media; $found_ids[$old_m_media]["new_id"] = $new_media; //$gedrec = preg_replace("/0 @(.*)@ OBJE/", "0 @$new_media@ OBJE", $gedrec); //-- record was replaced by a duplicate record so leave it out. return ''; } return $gedrec; } if ($keepmedia) { $old_linked_media = $gBitDb->getAll("SELECT mm_media, mm_gedrec FROM {$TBLPREFIX}media_mapping WHERE mm_gid=? AND mm_gedfile=?", array($gid, $GEDCOMS[$FILE]['id'])); } //-- check to see if there are any media records //-- if there aren't any media records then don't look for them just return $pt = preg_match("/\\d OBJE/", $gedrec, $match); if ($pt > 0) { //-- go through all of the lines and replace any local //--- OBJE to referenced OBJEs $newrec = ""; $lines = explode("\n", $gedrec); $ct_lines = count($lines); $inobj = false; $processed = false; $objlevel = 0; $objrec = ""; $count = 1; foreach ($lines as $key => $line) { if (!empty($line)) { // NOTE: Match lines that resemble n OBJE @0000@ // NOTE: Renumber the old ID to a new ID and save the old ID // NOTE: in case there are more references to it $level = $line[0]; //-- putting this code back since $objlevel, $objrec, etc vars will be //-- reset in sections after this if ($objlevel > 0 && $level <= $objlevel) { $objref = insert_media($objrec, $objlevel, $update, $gid, $count); $count++; // NOTE: Add the new media object to the record $newrec .= $objref; // NOTE: Set the details for the next media record $objlevel = 0; $inobj = false; } if (preg_match("/[1-9]\\sOBJE\\s@(.*)@/", $line, $match) != 0) { // NOTE: Set object level $objlevel = $level; $inobj = true; $objrec = $line . "\n"; } elseif (preg_match("/[1-9]\\sOBJE/", $line, $match)) { // NOTE: Set the details for the next media record $objlevel = $level; $inobj = true; $objrec = $line . "\n"; } else { $ct = preg_match("/(\\d+)\\s(\\w+)(.*)/", $line, $match); if ($ct > 0) { if ($inobj) { $objrec .= $line . "\n"; } else { $newrec .= $line . "\n"; } } else { $newrec .= $line . "\n"; } } } } //-- make sure the last line gets handled if ($inobj) { $objref = insert_media($objrec, $objlevel, $update, $gid, $count); $count++; $newrec .= $objref; // NOTE: Set the details for the next media record $objlevel = 0; $inobj = false; } } else { $newrec = $gedrec; } if ($keepmedia) { $newrec = trim($newrec) . "\n"; foreach ($old_linked_media as $i => $row) { $newrec .= trim($row[1]) . "\n"; } } return trim($newrec); }
/** * generate OSA from Quotations * * @param int quotation_id * @return int count of OSA Lines generated */ function JKY_generate_osa($the_id) { $db = Zend_Registry::get('db'); $sql = 'SELECT *' . ' FROM Quotations' . ' WHERE id = ' . $the_id; $my_quotation = $db->fetchRow($sql); $my_needed_at = $my_quotation['needed_at']; if ($my_needed_at == null) { $my_needed_at = get_time(); } $my_osa_id = get_next_id('OSAs'); $sql = 'INSERT OSAs' . ' SET id =' . $my_osa_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', osa_number =' . $my_osa_id . ', quotation_id =' . $the_id . ', ordered_at ="' . get_time() . '"' . ', needed_at ="' . $my_needed_at . '"' . ', quoted_pieces =' . $my_quotation['quoted_pieces'] . ', ordered_pieces =' . $my_quotation['quoted_pieces'] . ', remarks ="' . $my_quotation['remarks'] . '"'; if ($my_quotation['customer_id']) { $sql .= ', customer_id=' . $my_quotation['customer_id']; } if ($my_quotation['salesman_id']) { $sql .= ', salesman_id=' . $my_quotation['salesman_id']; } log_sql('OSAs', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'OSAs', $my_osa_id); $sql = 'SELECT *' . ' FROM QuotLines' . ' WHERE parent_id = ' . $the_id; $my_rows = $db->fetchAll($sql); $my_count = 0; foreach ($my_rows as $my_row) { $my_osa_line_id = get_next_id('OSA_Lines'); $sql = 'INSERT OSA_Lines' . ' SET id =' . $my_osa_line_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', parent_id =' . $my_osa_id . ', peso =' . $my_row['peso'] . ', quoted_units =' . $my_row['quoted_units'] . ', units =' . $my_row['units'] . ', quoted_pieces =' . $my_row['quoted_pieces'] . ', ordered_pieces =' . $my_row['quoted_pieces'] . ', quoted_weight =' . $my_row['quoted_weight'] . ', ordered_weight =' . $my_row['quoted_weight'] . ', remarks ="' . $my_row['remarks'] . '"'; if ($my_row['product_id']) { $sql .= ', product_id=' . $my_row['product_id']; } log_sql('OSA_Lines', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'OSA_Lines', $my_osa_line_id); $sql = 'SELECT *' . ' FROM QuotColors' . ' WHERE parent_id = ' . $my_row['id']; $my_colors = $db->fetchAll($sql); foreach ($my_colors as $my_color) { $my_osa_color_id = get_next_id('OSA_Colors'); if ($my_row['units'] == 0) { $my_quoted_pieces = ceil($my_color['quoted_units'] / $my_row['peso']); $my_quoted_weight = $my_color['quoted_units']; } else { $my_quoted_pieces = ceil($my_color['quoted_units'] / $my_row['units']); $my_quoted_weight = $my_color['quoted_units'] * $my_row['peso']; } $sql = 'INSERT OSA_Colors' . ' SET id =' . $my_osa_color_id . ', updated_by =' . get_session('user_id') . ', updated_at ="' . get_time() . '"' . ', parent_id =' . $my_osa_line_id . ', quoted_pieces =' . $my_quoted_pieces . ', quoted_weight =' . $my_quoted_weight . ', ordered_pieces =' . $my_quoted_pieces . ', ordered_weight =' . $my_quoted_weight; // if ($my_quotation['customer_id']) $sql .= ', customer_id=' . $my_quotation['customer_id']; if ($my_row['machine_id']) { $sql .= ', machine_id=' . $my_row['machine_id']; } // if ($my_row['product_id']) $sql .= ', product_id=' . $my_row['product_id']; if ($my_color['color_id']) { $sql .= ', color_id=' . $my_color['color_id']; } log_sql('OSA_Colors', 'INSERT', $sql); $db->query($sql); insert_changes($db, 'OSA_Colors', $my_osa_color_id); } $my_count++; } $sql = 'UPDATE Quotations' . ' SET status = "Active"' . ' WHERE id = ' . $the_id; log_sql('Quotations', 'UPDATE', $sql); $db->query($sql); insert_changes($db, 'Quotations', $the_id); return $my_count; }