function findQID($game_id, $questionNum) { global $conn; $sql = "SELECT * FROM `questions` WHERE gameid ='" . $game_id . "' AND questionNum='" . $questionNum . "'"; $result = $conn->query($sql); echo $sql; if ($result) { if ($row = $result->fetch_assoc()) { //echo $this->location->lat; /* $answer=new self(); $answer->location=new LatLong($row["lat"],$row["longg"]); $answer->questionNum=$questionNum; $answer->name=$row["wording"]; $answer->value=$row["answer"];*/ $word = $row["wording"]; $type = $row["type"]; $id = findID($type, $word); if ($type == "geo") { $id->location = new LatLong($row["lat"], $row["longg"]); } else { $id->answer = $row["answer"]; } return $id; //return $type.$id; } } }
function docsvupload() { global $dcl_info, $g_oSec; commonHeader(); if (!$g_oSec->HasPerm(DCL_ENTITY_WORKORDER, DCL_PERM_IMPORT)) { return PrintPermissionDenied(); } if (($sTempFileName = DCL_Sanitize::ToFileName('userfile')) === null) { return PrintPermissionDenied(); } // Open the file as text - let PHP take care of line // delimiter differences $hFile = fopen($sTempFileName, 'r'); if (!$hFile) { trigger_error(STR_BO_CSVUPLOADERR); return; } // Get the line containing field names $newjcns = array(); $line = 1; $fields = fgetcsv($hFile, 1000); // Define a useful function for mapping a short name to ID // It is really ineffective to instantiate a new object for // each field! function findID($obj, $table, $value, $pk = 'id', $fd = 'short', $fd2 = '', $val2 = '') { $sSQL = "SELECT {$pk} FROM {$table} WHERE {$fd} = " . $obj->Quote($value); if ($fd2 != '' && $val2 != '') { $sSQL .= " AND {$fd2} = {$val2}"; } $obj->Query($sSQL); if ($obj->next_record()) { return $obj->f(0); } else { return -1; } } $objWorkorder =& CreateObject('dcl.dbWorkorders'); $objTemp =& CreateObject('dcl.dbWorkorders'); $objProjectmap =& CreateObject('dcl.dbProjectmap'); $objWtch =& CreateObject('dcl.boWatches'); while ($data = fgetcsv($hFile, 1000)) { $line++; $projectid = -1; $module_id = -1; $objWorkorder->Clear(); while (list($i, $val) = each($data)) { if (!is_numeric($val)) { // we may need to convert smth switch ($fields[$i]) { case 'product': $new_val = findID($objTemp, 'products', $val); break; case 'module_id': $module_id = $val; continue; break; case 'account': $new_val = findID($objTemp, 'accounts', $val); break; case 'wo_type_id': $new_val = findID($objTemp, 'dcl_wo_type', $val, 'wo_type_id', 'type_name'); break; case 'entity_source_id': $new_val = findID($objTemp, 'dcl_entity_source', $val, 'entity_source_id', 'entity_source_name'); break; case 'priority': $new_val = findID($objTemp, 'priorities', $val); break; case 'severity': $new_val = findID($objTemp, 'severities', $val); break; case 'responsible': $new_val = findID($objTemp, 'personnel', $val); break; case 'project': $new_val = findID($objTemp, 'dcl_projects', $val, 'projectid', 'name'); $projectid = $new_val; break; default: $new_val = $val; } if ($new_val == -1) { // An error on mapping trigger_error(sprintf(STR_BO_CSVMAPERR, $fields[$i], $line), E_USER_ERROR); continue 2; // On to next line in the file } $val = $new_val; } else { if ($fields[$i] == 'module_id') { $module_id = $val; } else { if (!$this->verifyID($fields[$i], $val)) { // An error on mapping trigger_error(sprintf(STR_BO_CSVMAPERR, $fields[$i], $line), E_USER_ERROR); continue 2; // On to next line in the file } } } if ($fields[$i] != 'project' && $fields[$i] != 'module_id') { // This will ignore nonexisting members // Only works in PHP4 because Clear() initializes each field! if (isset($objWorkorder->{$fields}[$i])) { $objWorkorder->{$fields}[$i] = $val; } } } // Lookup module if specified if ($module_id != -1) { if (is_numeric($module_id)) { // just verify this module exists for this product if ($objTemp->ExecuteScalar("SELECT COUNT(*) FROM dcl_product_module WHERE product_module_id = {$module_id} AND product_id = " . $objWorkorder->product) > 0) { $objWorkorder->module_id = $module_id; } } else { $objWorkorder->module_id = findID($objTemp, 'dcl_product_module', $module_id, 'product_module_id', 'module_name', 'product_id', $objWorkorder->product); } } $objWorkorder->createby = $GLOBALS['DCLID']; $objWorkorder->Add(); if ($objWorkorder->jcn > 0) { if ($projectid > 0) { // Project specified, so try to add it $objProjectmap->projectid = $projectid; $objProjectmap->jcn = $objWorkorder->jcn; $objProjectmap->seq = $objWorkorder->seq; $objProjectmap->Add(); } // Add it to our new work order collection $newjcns[] = $objWorkorder->jcn; // Send notification $objWtch->sendNotification($objWorkorder, '4,1'); } } if (count($newjcns) > 0) { // Display imported work orders $objView =& CreateObject('dcl.boView'); $objView->style = 'report'; $objView->title = 'Work Order CSV Upload Results'; $objView->AddDef('filter', 'jcn', $newjcns); $objView->AddDef('order', 'jcn'); $objView->AddDef('columns', '', array('jcn', 'seq', 'responsible.short', 'products.name', 'statuses.name', 'eststarton', 'deadlineon', 'etchours', 'totalhours', 'summary')); $objView->AddDef('columnhdrs', '', array(STR_WO_JCN, STR_WO_SEQ, STR_WO_RESPONSIBLE, STR_WO_PRODUCT, STR_WO_STATUS, STR_WO_ESTSTART, STR_WO_DEADLINE, STR_WO_ETCHOURS, STR_WO_ACTHOURS, STR_WO_SUMMARY)); $objHV =& CreateObject('dcl.htmlWorkOrderResults'); $objHV->Render($objView); } }