\r\n";
return $message;
}
function get_sector($sector_id)
{
$query = "select * from all_sectors where sector_id=".$sector_id;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ( $_REQUEST['lng'] == "ar" )
return $row['sector_ar_desc'];
else
return $row['sector_en_desc'];
}
function get_country_name($country_code)
{
$query = "select * from countries where country_zip_code='".$country_code."'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
if ( $_REQUEST['lng'] == "ar" )
return $row['country_ar_name'];
else
return $row['country_en_name'];
}
function show_details_failure($dir,$db_connection,$master_id,$submit_date)
{
$query = "delete from inquiry_master where id=".$master_id." and submit_date='".$submit_date."'";
$result = mysql_query($query);
echo "
".($dir == "rtl" ? "نأسف لم نستطع تسجيل الطلبية, الرجاء المحاولة فيما بعد إن واجهتك هذه المشكلة مرة أخرى, الرجاء إعلام مشرف الموقع من خلال هذا الرابط" : "Sorry, we couldn't submit your inquiry, Please try again later, and if you face the same problem, please contact us through this link")."
";
}
function show_master_failure($dir)
{
echo "
".($dir == "rtl" ? "نأسف لم نستطع تسجيل الطلبية, الرجاء المحاولة فيما بعد إن واجهتك هذه المشكلة مرة أخرى, الرجاء إعلام مشرف الموقع من خلال هذا الرابط" : "Sorry, we couldn't submit your inquiry, Please try again later, and if you face the same problem, please contact us through this link")."
";
}
function show_err_message($dir,$err_message)
{
echo "
".$err_message."
";
}
function create_sectors_select_list($dir)
{
$sectors = new sectors_factory();
@ $all_sectors = $sectors->create_sectors_list("select * from all_sectors order by sector_en_desc ASC");
if ( $all_sectors && count($all_sectors) > 0 )
{
$returnedstring = "";
$returnedstring.="\n";
return $returnedstring;
}
else
{
return "\n";
}
}
function create_countries_select_list($dir)
{
return '
';
}
function create_preferred_currencies_list()
{
$str = "
USD - US Dollars
EUR - Euros
GBP - UK Pounds
CAD - Canadian
Dollars
AUD - Australian
Dollars
CHF - Swiss Francs
RUR - Russian Rubles
CNY - Chinese Yuan
ZAR - South African
Rand
MEX - Mexican Pesos
JPY - Japanese
Yen
Local Currency
";
return $str;
}
//save the inquiry master
function save_inquiry_master($db_connection,$coname,$phone,$fax,$mobile,$email,$curr,$period,$EX_FOB,$sector,$country,$validity,$payment,$submit_date,$closing_date,$title)
{
if ( $EX_FOB != "CF" )
$country = "";
else
$EX_FOB = "C&F";
$currstr = implode(",",$curr);
$company_id = $_REQUEST['send_to'] != "" ? $_REQUEST['send_to'] : $_SESSION['coid'];
$query = "insert into inquiry_master (company_id,company_name,phone,fax,mobile,e_mail,sector_id,del_point,CF_country,".
"del_time,quotion_validity,closing_date,payment_terms,currency,submit_date,title) values(".$company_id.",'".$coname."','".$phone."','".$fax
."','".$mobile."','".$email."',".$sector.",'".$EX_FOB."','".$country."',".$period.",".$validity.",'".$closing_date."','".$payment."','".
$currstr."','".$submit_date."','".$title."')";
$result = mysql_query($query);
if ( !$result )
return false;
else
return true;
}
function get_master_id($db_connection,$coname,$submit_date)
{
$query = "select id from inquiry_master where company_name='".$coname."' and submit_date='".$submit_date."' order by id DESC";
$result = mysql_query($query);
if ( !$result )
return false;
else
{
$row = mysql_fetch_array($result);
return $row['id'];
}
}
function save_inquiry_detail($db_connection,$master_id,$i,$desc,$qty)
{
$i = $i+1;
$query = "insert into inquiry_details (master_id,item_id,item_desc,item_qty) values(".
$master_id.",".$i.",'".$desc."',".$qty.")";
$result = mysql_query($query);
if ( !$result )
return false;
else
return true;
}
function delete_inquiry($master_id)
{
$dir = $_REQUEST['lng'] == "ar" ? "rtl" : "ltr";
$connection = new Connector();
$db_connection = $connection->connect();
if ($db_connection != false)
{
$query = "delete from inquiry_master where id=".$master_id;
$result = mysql_query($query);
$query = "delete from inquiry_details where master_id=".$master_id;
$result = mysql_query($query);
if ( $result )
{
$GLOBALS['message_type'] = 1;
$GLOBALS['message'] = $dir == "rtl" ? "لقد تم إلغاء الطلبية بنجاح" : "Inquiry was successfully canceled";
}
else
{
$GLOBALS['message_type'] = 2;
$GLOBALS['message'] = $dir == "rtl" ? "نأسف، لم نستطع إلغاء الطلبية" : "Sorry, We could't cancel the inquiry";
}
}
}
function send_inquiry()
{
if ( $GLOBALS['sent_before'] != 1 )
{
$subject =$_REQUEST['lng'] == "ar" ? "الطلبية الجديدة التي أرسلتها من موقعنا" : "The new inquiry you sent from our site";
send_mail_to_submitter($subject);
/*$GLOBALS['mail_counter'] = 1;
$_SESSION['not_me'] = 1;
send_mail_to_matchers();
$GLOBALS['sent_before'] = 1;*/
}
}
function send_mail_to_submitter($subject)
{
$message = "\n
\n
";
$message .="
";
$message .="
";
$message .="";
$message .="
";
$message .="
";
$message .="
";
$message .= $GLOBALS['mail_body']."";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$_POST['co_name']." <".$_POST['mail'].">\r\n";
$headers .= "To: SGEDCO , ".$_POST['co_name']." <".$_POST['mail']."> \r\n";
$headers .= "Reply-To: ".$_POST['co_name']." <".$_POST['mail'].">\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";
$headers .= "X-Mailer: The arab mart mailer";
$mail = "anis@cedece.com";
@ mail($mail, $subject, $message, $headers);
}
function create_mail_body()
{
$title = $_POST['title'];
$coname = $_POST['co_name'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$mobile = $_POST['mobile'];
$email = $_POST['mail'];
$period = $_POST['period'];
$EX_FOB = $_POST['EX_FOB'];
$country = $_POST['country'];
$validity = $_POST['validity'];
$payment = $_POST['payment'];
$submit_date = date('Y-m-d');
$closing_date = $_POST['close_date'];
$descriptions = $_POST['DESC'];
$QTYs = $_POST['QTY'];
$all_done = true;
$no_of_item = 1;
$description = array();
$QTY = array();
for ( $i = 0 ; $i < 20 ; $i++ )
{
if ( $QTYs[$i] != "" )
{
array_push($description,$descriptions[$i]);
array_push($QTY,$QTYs[$i]);
}
}
$message = echo_inquiry($coname,$phone,$fax,$mobile,$email,$period,$EX_FOB,$country,$validity,$payment,$submit_date,$closing_date,$description,$QTY,"ltr",$title);
return $message;
}
function send_mail_to_matchers($master_id,$sector_id)
{
$connection = new Connector();
$db_connection = $connection->connect();
if ($db_connection != false)
{
$subject =$_REQUEST['lng'] == "ar" ? "طلبية جديدة" : "New inquiry submitted";
if ( $_REQUEST['send_to'] != "" )
{
$query = "select * from all_companies where id=".$_REQUEST['send_to'];
}
else
{
$query = "select all_companies.*,company_sector.*, all_companies.id as req_id from all_companies,company_sector where company_sector.sector_id=".$sector_id.
" and all_companies.company_id=company_sector.company_id and all_companies.receive_inquiries='yes'".
" and all_companies.membership_id > 1 and all_companies.id !=".$_SESSION['coid'];
}
$result = mysql_query($query);
$num_of_rows = mysql_num_rows($result);
if ( $num_of_rows > 0 )
{
for ( $i = 0 ; $i < $num_of_rows ; $i++ )
{
$row = mysql_fetch_array($result);
$coname = $_REQUEST['lng'] == "ar" ? $row['company_ar_name'] : $row['company_en_name'];
if ( $coname == "" )
{
$coname = $row['company_ar_name'];
}
if ( $coname == "" )
{
$coname = $row['company_en_name'];
}
save_inquiry_into_basket($master_id,$row['req_id']);
$dir = get_pref_languages($row['pref_language']);
$GLOBALS['mail_body'] = create_mail_body($master_id,$dir);
send_mail_to_submitter($master_id,$row['e_mail'],$coname,$subject);
}
$GLOBALS['message_type'] = 1;
$GLOBALS['message'] = $dir == "rtl" ? "لقد تم إرسال الطلبية بنجاح لـ ( ".$num_of_rows." ) شركة" : "Inquiry was successfully sent to ( ".$num_of_rows." ) company (s)";
}
else
{
$GLOBALS['message_type'] = 2;
$GLOBALS['message'] = $dir == "rtl" ? "نأسف، لم نستطع إرسال الطلبية" : "Sorry, We couldn't send your inquiry";
}
}
else
{
$GLOBALS['message_type'] = 2;
$GLOBALS['message'] = $dir == "rtl" ? "نأسف، لم نستطع إرسال الطلبية" : "Sorry, We couldn't send your inquiry";
}
}
function get_pref_languages($lang)
{
if ( $lang == "Arabic" )
return "rtl";
else
return "ltr";
}
function save_inquiry_into_basket($master_id,$company_id)
{
$connection = new Connector();
$db_connection = $connection->connect();
if ($db_connection != false)
{
$query = "insert into inquiry_basket values(".$master_id.",".$company_id.")";
$result = mysql_query($query);
}
}
?>