function addLead(){ global $DB; global $newname; // if its new if(!isset($_REQUEST['e'])){ // the created by $createdby = 'createdby_repid = '.$_SESSION['loggedin'].', '; // created on $createdon = 'createdon = CURDATE(), '; // update & where $insertOrUpdate = 'INSERT INTO leads SET '; $where = ''; }else{ // insert & where $insertOrUpdate = 'UPDATE leads SET '; $where = ' WHERE id = '.$_REQUEST['e']; $createdby = ''; $createdon = ''; } $reason_repid = isset($_REQUEST['reason_repid'])?$DB->safe($_REQUEST['reason_repid']):0; $sql = $insertOrUpdate. "jobname = '".$DB->safe($_REQUEST['jobname'])."', quotefile = '".$DB->safe(addslashes(changeFileName()))."', company = '".$DB->safe($_REQUEST['company'])."', customer = '".$DB->safe($_REQUEST['customer'])."', targetdate = '".$DB->safe(dateFixSQL($_REQUEST['targetdate']))."', dateclosed = '".$DB->safe(dateFixSQL($_REQUEST['dateclosed']))."', rep = '".$DB->safe($_REQUEST['rep'])."', estimated = '".$DB->safe($_REQUEST['estimated'])."', quotedby_repid = ".$DB->safe($_REQUEST['quotedby_repid']).", status = '".$DB->safe($_REQUEST['status'])."', reason = '".$_REQUEST['reason']."', reason_repid = ".$reason_repid.", lastupdated = CURDATE(), lastupdatedby_repid = ".$_SESSION['loggedin'].", ".$createdby." ".$createdon." comments = '".$DB->safe($_REQUEST['comments'])."'" .$where; if($DB->query($sql)){ $editIt = (isset($_REQUEST['e']))?$_REQUEST['e']:$DB->lastInsertedId(); unset($_SESSION['startedfile']); print '1:'.$editIt; /* print '<pre>'; print_r($_REQUEST); print '</pre>'; */ }else{ print '0:'.mysql_error(); } }
function getCriteria(){ global $numCols; $search_fields = array(); // jobname if(strlen($_REQUEST['search_jobname']) > 0){ $search_fields []='jobname LIKE \'%'.$_REQUEST['search_jobname'].'%\''; } // company if(strlen($_REQUEST['search_company']) > 0){ $search_fields []= 'company LIKE \'%'.$_REQUEST['search_company'].'%\''; } // company if(strlen($_REQUEST['search_customer']) > 0){ $search_fields []= 'customer LIKE \'%'.$_REQUEST['search_customer'].'%\''; } // rep if(strlen($_REQUEST['rep']) > 0 && $_REQUEST['rep_check']){ $search_fields []= 'rep = '.$_REQUEST['rep']; } // status if(strlen($_REQUEST['search_status']) > 0){ if($_REQUEST['search_status'] != "0"){ $search_fields []= 'status = \''.$_REQUEST['search_status'].'\''; }else{ $search_fields []= 'status != "***"'; } } // target date if(strlen($_REQUEST['search_target_before']) > 0 && strlen($_REQUEST['search_target_after']) > 0){ $search_fields []= '(targetdate >= \''.dateFixSQL($_REQUEST['search_target_after']).'\' AND targetdate <= \''.dateFixSQL($_REQUEST['search_target_before']).'\')'; }else{ // target date before if(strlen($_REQUEST['search_target_before']) > 0){ $search_fields []= 'targetdate <= \''.$_REQUEST['search_target_before'].'\''; } // target dates after if(strlen($_REQUEST['search_target_after']) > 0){ $search_fields []= 'targetdate >= \''.$_REQUEST['search_target_after'].'\''; } } //estimated low & high if(strlen($_REQUEST['estimated_low']) > 0 && strlen($_REQUEST['estimated_high']) > 0){ $search_fields []= '(estimated >= '.$_REQUEST['estimated_low'].' AND estimated <= '.$_REQUEST['estimated_high'].')'; }else{ if(strlen($_REQUEST['estimated_low']) > 0){ $search_fields []= 'estimated = '.$_REQUEST['estimated_low']; } if(strlen($_REQUEST['estimated_high']) > 0){ $search_fields []= 'estimated = '.$_REQUEST['estimated_high']; } } $sql_criteria = ''; foreach($search_fields as $k => $v){ $type = ($_REQUEST['reqtype'] == 'all')?' AND ':' OR '; $and = ($k > 0)?$type:''; $sql_criteria .= $and.$v; } return $sql_criteria; }