function InsertRecord($arr, $recInd)
{
    global $goodlines, $conn, $error_message, $keys_present, $keys, $strOriginalTableName, $strTableName, $eventObj, $locale_info, $auditObj;
    $ret = 1;
    $rawvalues = array();
    foreach ($arr as $key => $val) {
        $rawvalues[$key] = $val;
        $type = GetFieldType($key);
        if (!NeedQuotes($type)) {
            $value = (string) $val;
            $value = str_replace(",", ".", $value);
            if (strlen($value) > 0) {
                $value = str_replace($locale_info["LOCALE_SCURRENCY"], "", $value);
                $arr[$key] = 0 + $value;
            } else {
                $arr[$key] = NULL;
            }
        }
    }
    $retval = true;
    if ($eventObj->exists('BeforeInsert')) {
        $retval = $eventObj->BeforeInsert($rawvalues, $arr);
    }
    if ($retval) {
        $fields = array_keys($arr);
        foreach ($fields as $key => $val) {
            $fields_list[$key] = AddFieldWrappers(GetFullFieldName($val));
        }
        $values_list = "";
        foreach ($arr as $key => $val) {
            if (!is_null($arr[$key])) {
                $values_list .= add_db_quotes($key, $val) . ", ";
            } else {
                $values_list .= "NULL, ";
            }
        }
        if (strlen($values_list) > 0) {
            $values_list = substr($values_list, 0, strlen($values_list) - 2);
        }
        $sql = "insert into " . AddTableWrappers($strOriginalTableName) . " (" . implode(",", $fields_list) . ") values (" . $values_list . ")";
        if (db_exec_import($sql, $conn)) {
            $goodlines++;
            if ($auditObj) {
                $aKeys = GetKeysArray($arr, true);
                $auditObj->LogAdd($strTableName, $arr, $aKeys);
            }
        } else {
            $temp_error_message = "<b>Error:</b> in the line: " . implode(",", $arr) . '&nbsp;&nbsp;<a linkType="debugOpener" recId="' . $recInd . '" href="" onclick="importMore(' . $recInd . ');">More info</a><br>';
            $temp_error_message .= '<div id="importDebugInfoTable' . $recInd . '" cellpadding="3" cellspacing="1" align="center" style="display: none;"><p class="error">SQL query: ' . $sql . '; </p><p class="error">DB error: ' . db_error($conn) . ';</p></div>';
            $temp_error_message .= "<br><br>";
            // we'll try to update the record
            if ($keys_present) {
                $sql = "update " . AddTableWrappers($strOriginalTableName) . " set ";
                $sqlset = "";
                $where = " where ";
                foreach ($fields as $k => $val) {
                    if (!in_array(AddFieldWrappers($fields[$k]), $keys)) {
                        if (!is_null($arr[$val])) {
                            $sqlset .= $fields_list[$k] . "=" . add_db_quotes($val, $arr[$val]) . ", ";
                        } else {
                            $sqlset .= $fields_list[$k] . "=NULL, ";
                        }
                    } else {
                        $where .= $fields_list[$k] . "=" . add_db_quotes($val, $arr[$val]) . " and ";
                    }
                }
                if (strlen($sqlset) > 0) {
                    $sql .= substr($sqlset, 0, strlen($sqlset) - 2);
                }
                $where = substr($where, 0, strlen($where) - 5);
                $sql .= " " . $where;
                $rstmp = db_query("select * from " . AddTableWrappers($strOriginalTableName) . " " . $where, $conn);
                $data = db_fetch_array($rstmp);
                if ($data) {
                    if ($auditObj) {
                        foreach ($data as $key => $val) {
                            $auditOldValues[$key] = $val;
                        }
                    }
                    if (db_exec_import($sql, $conn)) {
                        // update successfull
                        $goodlines++;
                        if ($auditObj) {
                            $aKeys = GetKeysArray($arr);
                            $auditObj->LogEdit($strTableName, $arr, $auditOldValues, $aKeys);
                        }
                    } else {
                        echo 'not updated';
                        // update not successfull
                        $error_message .= $temp_error_message;
                        $ret = 0;
                    }
                } else {
                    $error_message .= $temp_error_message;
                    $ret = 0;
                }
            } else {
                $error_message .= $temp_error_message;
            }
        }
        return $ret;
    }
}
    $searchClauseObj = new SearchClause($params);
}
// array of vals
$response = array();
if (postvalue("start")) {
    $suggestAllContent = false;
}
$searchFor = postvalue('searchFor');
$searchField = GoodFieldName(postvalue('searchField'));
$strSecuritySql = SecuritySQL("Search", $strTableName);
if ($searchField == "") {
    $allSearchFields = GetTableData($strTableName, '.googleLikeFields', array());
}
// proccess fields and create sql
foreach ($allSearchFields as $f) {
    $fType = GetFieldType($f, $strTableName);
    // filter fields by type
    if (!IsCharType($fType) && !IsNumberType($fType) && !IsGuid($fType) || IsTextType($fType)) {
        continue;
    }
    // get suggest for field
    if (($searchField == '' || $searchField == GoodFieldName($f)) && CheckFieldPermissions($f)) {
        $where = "";
        $having = "";
        if (!$gQuery->IsAggrFuncField(GetFieldIndex($f) - 1)) {
            $where = $searchClauseObj->getSuggestWhere($f, $fType, $suggestAllContent, $searchFor);
        } elseif ($gQuery->IsAggrFuncField(GetFieldIndex($f) - 1)) {
            $having = $searchClauseObj->getSuggestWhere($f, $fType, $suggestAllContent, $searchFor);
        }
        // prepare common vals
        $sqlHead = "SELECT DISTINCT " . GetFullFieldName($f) . " ";
for ( $i=0; $i < count($xml_array['group_fields'])-1; $i++ ) {
	$aGroupFields[] = $xml_array['tables'][0]."_".$xml_array['group_fields'][$i]['name'];
}


$aTotFields=array();


foreach ( $inspect_fields as $fld ) {
	if(is_wr_db())
		$fld_type=WRGetFieldType($fld['table'].".".$fld['name']);
	elseif(is_wr_custom())
		$fld_type=WRCustomGetFieldType($fld['table'],$fld['name']);
	else
		$fld_type=GetFieldType($fld['name'],$fld['table']);	
	
	if ( !IsBinaryType($fld_type)) {
		$aTotFields[] = $fld['table']."_".$fld['name'];
	}
}

$ngFieldNames = array_diff( $aTotFields, $aGroupFields );


$arr_alias = array();
foreach ( $aGroupFields as $gr_name  ) {
	foreach ( $inspect_fields as $fld ) {
		if ( $gr_name == $fld['table']."_".$fld['name'] && !in_array($fld['table']."_".$fld['name'], $arr_alias)) {
			$arr_alias[] = $fld['table']."_".$fld['name'];
			$arr_page_order_fields["data"][] = $fld;
function BuildEditControl($field, $value, $format, $edit, $fieldNum = 0, $id = "", $validate, $additionalCtrlParams, &$pageObj)
{
    global $rs, $data, $strTableName, $filenamelist, $keys, $locale_info, $jscode;
    $inputStyle = 'style="';
    $inputStyle .= $additionalCtrlParams['style'] ? $additionalCtrlParams['style'] : '';
    //$inputStyle .= ($additionalCtrlParams['hidden'] ? 'display: none;' : '');
    $inputStyle .= '"';
    $cfieldname = GoodFieldName($field) . "_" . $id;
    $cfield = "value_" . GoodFieldName($field) . "_" . $id;
    $ctype = "type_" . GoodFieldName($field) . "_" . $id;
    $is508 = isEnableSection508();
    $strLabel = Label($field);
    if ($fieldNum) {
        $cfield = "value" . $fieldNum . "_" . GoodFieldName($field) . "_" . $id;
        $ctype = "type" . $fieldNum . "_" . GoodFieldName($field) . "_" . $id;
    }
    $type = GetFieldType($field);
    $arr = "";
    $iquery = "field=" . rawurlencode($field);
    $keylink = "";
    $arrKeys = GetTableKeys($strTableName);
    for ($j = 0; $j < count($arrKeys); $j++) {
        $keylink .= "&key" . ($j + 1) . "=" . rawurlencode($data[$arrKeys[$j]]);
    }
    $iquery .= $keylink;
    $isHidden = isset($additionalCtrlParams['hidden']) && $additionalCtrlParams['hidden'];
    echo '<span id="edit' . $id . '_' . GoodFieldName($field) . '_' . $fieldNum . '" class="runner-nowrap"' . ($isHidden ? ' style="display:none"' : '') . '">';
    if ($format == EDIT_FORMAT_FILE && $edit == MODE_SEARCH) {
        $format = "";
    }
    if ($format == EDIT_FORMAT_TEXT_FIELD) {
        if (IsDateFieldType($type)) {
            echo '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="date' . EDIT_DATE_SIMPLE . '">' . GetDateEdit($field, $value, 0, $fieldNum, $edit, $id, $pageObj);
        } else {
            if ($edit == MODE_SEARCH) {
                echo '<input id="' . $cfield . '" ' . $inputStyle . ' type="text" autocomplete="off" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" ' . GetEditParams($field) . ' value="' . htmlspecialchars($value) . '">';
            } else {
                echo '<input id="' . $cfield . '" ' . $inputStyle . ' type="text" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" ' . GetEditParams($field) . ' value="' . htmlspecialchars($value) . '">';
            }
        }
    } else {
        if ($format == EDIT_FORMAT_TIME) {
            echo '<input id="' . $ctype . '" ' . $inputStyle . ' type="hidden" name="' . $ctype . '" value="time">';
            $arr_number = parsenumbers((string) $value);
            if (count($arr_number) == 6) {
                $value = mysprintf("%d:%02d:%02d", array($arr_number[3], $arr_number[4], $arr_number[5]));
            }
            $timeAttrs = GetFieldData($strTableName, $field, "FormatTimeAttrs", array());
            if (count($timeAttrs)) {
                if ($timeAttrs["useTimePicker"]) {
                    $convention = $timeAttrs["hours"];
                    $loc = getLacaleAmPmForTimePicker($convention, true);
                    $tpVal = getValForTimePicker($type, $value, $loc['locale']);
                    echo '<input type="text" ' . $inputStyle . ' name="' . $cfield . '" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'id="' . $cfield . '" ' . GetEditParams($field) . ' value="' . htmlspecialchars($tpVal['val']) . '">';
                    echo '&nbsp;';
                    echo '<img class="runner-imgclock" src="images/clock.gif" alt="Time" border="0" style="margin:4px 0 0 6px; visibility: hidden;" id="trigger-test-' . $cfield . '" />';
                } else {
                    echo '<input id="' . $cfield . '" ' . $inputStyle . ' type="text" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" ' . GetEditParams($field) . ' value="' . htmlspecialchars($value) . '">';
                }
            }
        } else {
            if ($format == EDIT_FORMAT_TEXT_AREA) {
                $nWidth = GetNCols($field);
                $nHeight = GetNRows($field);
                if (UseRTE($field)) {
                    $value = RTESafe($value);
                } else {
                    echo '<textarea id="' . $cfield . '" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" style="';
                    if (!isMobile()) {
                        echo "width: " . $nWidth . "px;";
                    }
                    echo 'height: ' . $nHeight . 'px;">' . htmlspecialchars($value) . '</textarea>';
                }
            } else {
                if ($format == EDIT_FORMAT_PASSWORD) {
                    echo '<input ' . $inputStyle . ' id="' . $cfield . '" type="Password" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" ' . GetEditParams($field) . ' value="' . htmlspecialchars($value) . '">';
                } else {
                    if ($format == EDIT_FORMAT_DATE) {
                        echo '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="date' . DateEditType($field) . '">' . GetDateEdit($field, $value, DateEditType($field), $fieldNum, $edit, $id, $pageObj);
                    } else {
                        if ($format == EDIT_FORMAT_RADIO) {
                            BuildRadioControl($field, $value, $fieldNum, $id, $edit);
                        } else {
                            if ($format == EDIT_FORMAT_CHECKBOX) {
                                if ($edit == MODE_ADD || $edit == MODE_INLINE_ADD || $edit == MODE_EDIT || $edit == MODE_INLINE_EDIT) {
                                    $checked = "";
                                    if ($value && $value != 0) {
                                        $checked = " checked";
                                    }
                                    echo '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="checkbox">';
                                    echo '<input id="' . $cfield . '" type="Checkbox" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '" ' . $checked . '>';
                                } else {
                                    echo '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="checkbox">';
                                    echo '<select id="' . $cfield . '" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . 'name="' . $cfield . '">';
                                    $val = array("", "on", "off");
                                    $show = array("", "True", "False");
                                    foreach ($val as $i => $v) {
                                        $sel = "";
                                        if ($value === $v) {
                                            $sel = " selected";
                                        }
                                        echo '<option value="' . $v . '"' . $sel . '>' . $show[$i] . '</option>';
                                    }
                                    echo "</select>";
                                }
                            } else {
                                if ($format == EDIT_FORMAT_DATABASE_IMAGE || $format == EDIT_FORMAT_DATABASE_FILE) {
                                    $disp = "";
                                    $strfilename = "";
                                    //$onchangefile="";
                                    if ($edit == MODE_EDIT || $edit == MODE_INLINE_EDIT) {
                                        $value = db_stripslashesbinary($value);
                                        $itype = SupposeImageType($value);
                                        $thumbnailed = false;
                                        $thumbfield = "";
                                        if ($itype) {
                                            if ($thumbnailed) {
                                                $disp = "<a ";
                                                if (IsUseiBox($field, $strTableName)) {
                                                    $disp .= " rel='ibox'";
                                                } else {
                                                    $disp .= " target=_blank";
                                                }
                                                $disp .= " href=\"imager.php?table=" . GetTableURL($strTableName) . "&" . $iquery . "&rndVal=" . rand(0, 32768) . "\">";
                                                $disp .= "<img id=\"image_" . GoodFieldName($field) . "_" . $id . "\" name=\"" . $cfield . "\" border=0";
                                                if (isEnableSection508()) {
                                                    $disp .= " alt=\"Image from DB\"";
                                                }
                                                $disp .= " src=\"imager.php?table=" . GetTableURL($strTableName) . "&field=" . rawurlencode($thumbfield) . "&alt=" . rawurlencode($field) . $keylink . "&rndVal=" . rand(0, 32768) . "\">";
                                                $disp .= "</a>";
                                            } else {
                                                $disp = '<img id="image_' . GoodFieldName($field) . '_' . $id . '" name="' . $cfield . '"';
                                                if (isEnableSection508()) {
                                                    $disp .= ' alt="Image from DB"';
                                                }
                                                $disp .= ' border=0 src="imager.php?table=' . GetTableURL($strTableName) . '&' . $iquery . "&rndVal=" . rand(0, 32768) . '">';
                                            }
                                        } else {
                                            if (strlen($value)) {
                                                $disp = '<img id="image_' . GoodFieldName($field) . '_' . $id . '" name="' . $cfield . '" border=0 ';
                                                if (isEnableSection508()) {
                                                    $disp .= ' alt="file"';
                                                }
                                                $disp .= ' src="images/file.gif">';
                                            } else {
                                                $disp = '<img id="image_' . GoodFieldName($field) . '_' . $id . '" name="' . $cfield . '" border="0"';
                                                if (isEnableSection508()) {
                                                    $disp .= ' alt=" "';
                                                }
                                                $disp .= ' src="images/no_image.gif">';
                                            }
                                        }
                                        //	filename
                                        if ($format == EDIT_FORMAT_DATABASE_FILE && !$itype && strlen($value)) {
                                            if (!($filename = @$data[GetFilenameField($field)])) {
                                                $filename = "file.bin";
                                            }
                                            $disp = '<a href="getfile.php?table=' . GetTableURL($strTableName) . '&filename=' . htmlspecialchars($filename) . '&' . $iquery . '".>' . $disp . '</a>';
                                        }
                                        //	filename edit
                                        if ($format == EDIT_FORMAT_DATABASE_FILE && GetFilenameField($field)) {
                                            if (!($filename = @$data[GetFilenameField($field)])) {
                                                $filename = "";
                                            }
                                            if ($edit == MODE_INLINE_EDIT) {
                                                $strfilename = '<br><label for="filename_' . $cfieldname . '">' . mlang_message("FILENAME") . '</label>&nbsp;&nbsp;<input type="text" ' . $inputStyle . ' id="filename_' . $cfieldname . '" name="filename_' . $cfieldname . '" size="20" maxlength="50" value="' . htmlspecialchars($filename) . '">';
                                            } else {
                                                $strfilename = '<br><label for="filename_' . $cfieldname . '">' . mlang_message("FILENAME") . '</label>&nbsp;&nbsp;<input type="text" ' . $inputStyle . ' id="filename_' . $cfieldname . '" name="filename_' . $cfieldname . '" size="20" maxlength="50" value="' . htmlspecialchars($filename) . '">';
                                            }
                                        }
                                        $strtype = '<br><input id="' . $ctype . '_keep" type="Radio" name="' . $ctype . '" value="file0" checked>' . mlang_message("KEEP");
                                        if ((strlen($value) || $edit == MODE_INLINE_EDIT) && !IsRequired($field)) {
                                            $strtype .= '<input id="' . $ctype . '_delete" type="Radio" name="' . $ctype . '" value="file1">' . mlang_message("DELETE");
                                        }
                                        $strtype .= '<input id="' . $ctype . '_update" type="Radio" name="' . $ctype . '" value="file2">' . mlang_message("UPDATE");
                                    } else {
                                        //	if Add mode
                                        $strtype = '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="file2">';
                                        if ($format == EDIT_FORMAT_DATABASE_FILE && GetFilenameField($field)) {
                                            $strfilename = '<br><label for="filename_' . $cfieldname . '">' . mlang_message("FILENAME") . '</label>&nbsp;&nbsp;<input type="text" ' . $inputStyle . ' id="filename_' . $cfieldname . '" name="filename_' . $cfieldname . '" size="20" maxlength="50">';
                                        }
                                    }
                                    if ($edit == MODE_INLINE_EDIT && $format == EDIT_FORMAT_DATABASE_FILE) {
                                        $disp = "";
                                    }
                                    echo $disp . $strtype;
                                    if ($edit == MODE_EDIT || $edit == MODE_INLINE_EDIT) {
                                        echo '<br>';
                                    }
                                    echo '<input type="File" ' . $inputStyle . ' id="' . $cfield . '" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . ' name="' . $cfield . '" >' . $strfilename;
                                    echo '<input type="Hidden" id="notempty_' . $cfieldname . '" value="' . (strlen($value) ? 1 : 0) . '">';
                                } else {
                                    if ($format == EDIT_FORMAT_LOOKUP_WIZARD) {
                                        BuildSelectControl($field, $value, $fieldNum, $edit, $id, $additionalCtrlParams, $pageObj);
                                    } else {
                                        if ($format == EDIT_FORMAT_HIDDEN) {
                                            echo '<input id="' . $cfield . '" type="Hidden" name="' . $cfield . '" value="' . htmlspecialchars($value) . '">';
                                        } else {
                                            if ($format == EDIT_FORMAT_READONLY) {
                                                echo '<input id="' . $cfield . '" type="Hidden" name="' . $cfield . '" value="' . htmlspecialchars($value) . '">';
                                            } else {
                                                if ($format == EDIT_FORMAT_FILE) {
                                                    $disp = "";
                                                    $strfilename = "";
                                                    $function = "";
                                                    if ($edit == MODE_EDIT || $edit == MODE_INLINE_EDIT) {
                                                        //	show current file
                                                        if (ViewFormat($field) == FORMAT_FILE || ViewFormat($field) == FORMAT_FILE_IMAGE) {
                                                            $disp = GetData($data, $field, ViewFormat($field)) . "<br>";
                                                        }
                                                        $filename = $value;
                                                        //	filename edit
                                                        $filename_size = 30;
                                                        if (UseTimestamp($field)) {
                                                            $filename_size = 50;
                                                        }
                                                        $strfilename = '<input type=hidden name="filenameHidden_' . $cfieldname . '" value="' . htmlspecialchars($filename) . '"><br>' . mlang_message("FILENAME") . '&nbsp;&nbsp;<input type="text" style="background-color:gainsboro" disabled id="filename_' . $cfieldname . '" name="filename_' . $cfieldname . '" size="' . $filename_size . '" maxlength="100" value="' . htmlspecialchars($filename) . '">';
                                                        if ($edit == MODE_INLINE_EDIT) {
                                                            $strtype = '<br><input id="' . $ctype . '_keep" type="Radio" name="' . $ctype . '" value="upload0" checked class="runner-uploadtype">' . mlang_message("KEEP");
                                                        } else {
                                                            $strtype = '<br><input id="' . $ctype . '_keep" type="Radio" name="' . $ctype . '" value="upload0" checked class="runner-uploadtype">' . mlang_message("KEEP");
                                                        }
                                                        if ((strlen($value) || $edit == MODE_INLINE_EDIT) && !IsRequired($field)) {
                                                            $strtype .= '<input id="' . $ctype . '_delete" type="Radio" name="' . $ctype . '" value="upload1" class="runner-uploadtype">' . mlang_message("DELETE");
                                                        }
                                                        $strtype .= '<input id="' . $ctype . '_update" type="Radio" name="' . $ctype . '" value="upload2" class="runner-uploadtype">' . mlang_message("UPDATE");
                                                    } else {
                                                        //	if Adding record
                                                        $filename_size = 30;
                                                        if (UseTimestamp($field)) {
                                                            $filename_size = 50;
                                                        }
                                                        $strtype = '<input id="' . $ctype . '" type="hidden" name="' . $ctype . '" value="upload2">';
                                                        $strfilename = '<br>' . mlang_message("FILENAME") . '&nbsp;&nbsp;<input type="text" id="filename_' . $cfieldname . '" name="filename_' . $cfieldname . '" size="' . $filename_size . '" maxlength="100">';
                                                    }
                                                    echo $disp . $strtype . $function;
                                                    if ($edit == MODE_EDIT || $edit == MODE_INLINE_EDIT) {
                                                        echo '<br>';
                                                    }
                                                    echo '<input type="File" id="' . $cfield . '" ' . (($edit == MODE_INLINE_EDIT || $edit == MODE_INLINE_ADD) && $is508 == true ? 'alt="' . $strLabel . '" ' : '') . ' name="' . $cfield . '" >' . $strfilename;
                                                    echo '<input type="Hidden" id="notempty_' . $cfieldname . '" value="' . (strlen($value) ? 1 : 0) . '">';
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (count($validate['basicValidate']) && array_search('IsRequired', $validate['basicValidate']) !== false) {
        echo '&nbsp;<font color="red">*</font></span>';
    } else {
        echo '</span>';
    }
}
 /**
  * Fill timepicker settings for current field
  */
 function fillTimePickSettings($field, $value = "")
 {
     $timeAttrs = GetFieldData($this->tName, $field, "FormatTimeAttrs", array());
     if (count($timeAttrs) && $timeAttrs["useTimePicker"]) {
         $convention = $timeAttrs["hours"];
         $locAmPm = getLacaleAmPmForTimePicker($convention, true);
         $tpVal = getValForTimePicker(GetFieldType($field), $value, $locAmPm['locale']);
         $range = array();
         if ($convention == 24) {
             for ($h = 0; $h < $convention; $h++) {
                 $range[] = $h;
             }
         } else {
             for ($h = 1; $h <= $convention; $h++) {
                 $range[] = $h;
             }
         }
         $minutes = array();
         for ($m = 0; $m < 60; $m += $timeAttrs["minutes"]) {
             $minutes[] = $m;
         }
         //settings
         $timePickSet = array('convention' => $convention, 'range' => $range, 'apm' => array($locAmPm['am'], $locAmPm['pm']), 'rangeMin' => $minutes, 'locale' => $locAmPm['locale'], 'showSec' => $timeAttrs["showSeconds"]);
         if (count($tpVal['dbtime']) > 0) {
             $timePickSet['hover'] = array('0' => $tpVal['dbtime'][3], '1' => $tpVal['dbtime'][4], '2' => $tpVal['dbtime'][5]);
         }
         if (!array_key_exists($field, $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'])) {
             $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$field] = array();
             $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$field]['timePick'] = $timePickSet;
         } elseif (!array_key_exists("timePick", $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$field])) {
             $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$field]['timePick'] = $timePickSet;
         }
         $this->fillControlsMap(array('controls' => array('open' => $tpVal['val'] ? true : false)), true, $field);
     }
 }
 function GetType()
 {
     return GetFieldType($this->m_strName, $this->m_strTable);
 }
 function getDisplayValue($index, $value)
 {
     global $locale_info;
     $field = $this->xml_array["group_fields"][$index]["name"];
     if ($value == "" || is_null($value)) {
         return "";
     }
     if ($this->table_type == "db") {
         $ftype = WRGetFieldType($this->FullFieldName($field));
     } elseif ($this->table_type == "project") {
         $ftype = GetFieldType($field, "");
     } else {
         $fields_type = WRGetAllCustomFieldType();
         $ftype = $fields_type[$field];
     }
     $arr = array();
     $arr = $this->xml_array["group_fields"];
     for ($i = 0; $i < count($arr) - 1; $i++) {
         if ($field == $arr[$i]["name"] && $index == $i) {
             $int_type = $arr[$i]["int_type"];
             break;
         }
     }
     if ($int_type == 0) {
         return $value;
     } elseif (IsNumberType($ftype)) {
         $start = $value - $value % $int_type;
         $end = $start + $int_type;
         return $start . " - " . $end;
     } elseif (IsCharType($ftype)) {
         return substr($value, 0, $int_type);
     } elseif (IsDateFieldType($ftype)) {
         $dvalue = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
         if (strlen($value) == 10) {
             $dvalue .= " " . substr($value, 8, 2) . "00:00";
         } elseif (strlen($value) == 12) {
             $dvalue .= " " . substr($value, 8, 2) . ":" . substr($value, 10, 2) . ":00";
         }
         $tm = db2time($dvalue);
         if (!count($tm)) {
             return "";
         }
         if ($int_type == 1) {
             // DATE_INTERVAL_YEAR
             return $tm[0];
         } elseif ($int_type == 2) {
             // DATE_INTERVAL_QUARTER
             return $tm[0] . "/Q" . $tm[1];
         } elseif ($int_type == 3) {
             // DATE_INTERVAL_MONTH
             return @$locale_info["LOCALE_SABBREVMONTHNAME" . $tm[1]] . " " . $tm[0];
         } elseif ($int_type == 4) {
             // DATE_INTERVAL_WEEK
             $dates = $this->getDatesByWeek($tm[1] + 1, $tm[0]);
             return format_shortdate(db2time($dates[0])) . ' - ' . format_shortdate(db2time($dates[1]));
         } elseif ($int_type == 5) {
             // DATE_INTERVAL_DAY
             return format_shortdate($tm);
         } elseif ($int_type == 6) {
             // DATE_INTERVAL_HOUR
             $tm[4] = 0;
             $tm[5] = 0;
             return str_format_datetime($tm);
         } elseif ($int_type == 7) {
             // DATE_INTERVAL_MINUTE
             $tm[5] = 0;
             return str_format_datetime($tm);
         } else {
             return str_format_datetime($tm);
         }
     }
 }
 /**
  * Check details and master tables field for types.They must be the same type.
  * Check details and master tables field for types.They must be the same type.
  * return true if they are same or if database is mySQL, otherwise returns false
  * @return bool
  */
 function checkDetailAndMasterFieldTypes()
 {
     if ($this->dbType == nDATABASE_MySQL) {
         return false;
     } else {
         // all details tables for which current table is master
         //$allDetailsTablesArr = GetDetailTablesArr($this->tName);
         for ($i = 0; $i < count($this->allDetailsTablesArr); $i++) {
             foreach ($this->masterKeysByD[$i] as $idx => $val) {
                 // get field types
                 $masterFieldType = GetFieldType($this->masterKeysByD[$i][$idx]);
                 $detailsFieldType = GetFieldType($this->detailKeysByD[$i][$idx], $this->allDetailsTablesArr[$i]['dDataSourceTable']);
                 // if different data types we can't use subQ
                 if ($masterFieldType != $detailsFieldType) {
                     return true;
                 }
             }
         }
         return false;
     }
 }
 function LogDelete($str_table, $values, $keys)
 {
     global $globalEvents;
     $retval = true;
     $table = $str_table;
     $arr = array();
     if ($globalEvents->exists("OnAuditLog")) {
         $retval = $globalEvents->OnAuditLog($this->strDelete, $this->params, $table, $keys, $values, $arr);
     }
     if ($retval) {
         if (count($keys) > 0) {
             $key = "";
             foreach ($keys as $idx => $val) {
                 if ($key != "") {
                     $key .= ",";
                 }
                 $key .= $val;
             }
         }
         $fp = $this->CreateLogFile();
         $str = format_datetime_custom(db2time(now()), "MMM dd,yyyy") . chr(9) . format_datetime_custom(db2time(now()), "HH:mm:ss") . chr(9) . $this->params[0] . chr(9) . $this->params[1] . chr(9) . $table . chr(9) . $this->strDelete . chr(9) . $key;
         $str_add = "";
         if ($this->logValueEnable($str_table)) {
             foreach ($values as $idx => $val) {
                 $v = "";
                 if (IsBinaryType(GetFieldType($idx, $str_table))) {
                     $v = "<binary value>";
                 } else {
                     $v = str_replace(array("\r\n", "\n", "\t"), " ", $val);
                     if (strlen($v) > 300) {
                         $v = substr($v, 0, 300);
                     }
                 }
                 if ($fp) {
                     $str_add .= $str . chr(9) . $idx . chr(9) . $v . "\r\n";
                 }
             }
         } else {
             $str_add = $str . "\r\n";
         }
         if ($fp) {
             fputs($fp, $str_add);
             fclose($fp);
         }
     }
     return $retval;
 }
 function SQLStatement($sql, $order, $pagesize, $connection, &$searchClauseObj, &$params)
 {
     // copy properties to object
     RunnerApply($this, $params);
     $this->searchClauseObj = $searchClauseObj;
     if (!is_array($sql)) {
         die('Invalid sql parameter');
     }
     global $reportCaseSensitiveGroupFields;
     $this->_originalSql = $sql;
     $start = 0;
     $fields = array();
     for ($i = 0; $i < count($this->repGroupFields); $i++) {
         for ($j = 0; $j < count($this->fieldsArr); $j++) {
             if ($this->repGroupFields[$i]['strGroupField'] == $this->fieldsArr[$j]['name']) {
                 $add = array();
                 $add['name'] = $this->fieldsArr[$j]['name'];
                 if (IsNumberType(GetFieldType($this->fieldsArr[$j]['name'], $this->tName))) {
                     $add['type'] = 'numeric';
                 } elseif (IsCharType(GetFieldType($this->fieldsArr[$j]['name'], $this->tName))) {
                     $add['type'] = 'char';
                     $add['case_sensitive'] = $reportCaseSensitiveGroupFields;
                 } elseif (IsDateFieldType(GetFieldType($this->fieldsArr[$j]['name'], $this->tName))) {
                     $add['type'] = 'date';
                 } else {
                     $add['type'] = 'char';
                 }
                 $add['interval'] = $this->repGroupFields[$i]['groupInterval'];
                 $add['viewformat'] = $this->fieldsArr[$j]['viewFormat'];
                 $add['rowsinsummary'] = 1;
                 if ($this->fieldsArr[$j]['totalMax'] || $this->fieldsArr[$j]['totalMin'] || $this->fieldsArr[$j]['totalAvg'] || $this->fieldsArr[$j]['totalSum']) {
                     $add['rowsinsummary']++;
                 }
                 if ($this->repLayout == REPORT_STEPPED) {
                     $add['rowsinheader'] = 1;
                 } elseif ($this->repLayout == REPORT_BLOCK) {
                     $add['rowsinheader'] = 0;
                 } elseif ($this->repLayout == REPORT_OUTLINE || $this->repLayout == REPORT_ALIGN) {
                     if ($j == count($this->fieldsArr) - 1) {
                         $add['rowsinheader'] = 2;
                     } else {
                         $add['rowsinheader'] = 1;
                     }
                 } elseif ($this->repLayout == REPORT_TABULAR) {
                     $add['rowsinheader'] = 0;
                 }
                 $fields[] = $add;
             }
         }
     }
     $this->_hasGroups = count($fields) > 0;
     foreach ($fields as $field) {
         $f = create_reportfield($field['name'], $field['type'], $field['interval'], 'grp');
         $start = $f->setStart($start);
         if (isset($field['case_sensitive'])) {
             $f->setCaseSensitive($field['case_sensitive']);
         }
         if (isset($field['rowsinsummary'])) {
             $f->_rowsInSummary = $field['rowsinsummary'];
         }
         if (isset($field['rowsinheader'])) {
             $f->_rowsInHeader = $field['rowsinheader'];
         }
         $f->_viewFormat = $field['viewformat'];
         $this->_fields[] = $f;
     }
     // order
     if ($order) {
         $order_in = array();
         $order_out = array();
         $order_old = array();
         foreach ($order as $o) {
             $order_in[] = $o[2] . ' as ' . cached_ffn('originalorder' . $o[0]);
             $order_out[] = cached_ffn('originalorder' . $o[0]) . ' ' . $o[1];
             $groupField = false;
             for ($i = 0; $i < count($this->repGroupFields); $i++) {
                 for ($j = 0; $j < count($this->fieldsArr); $j++) {
                     if ($this->repGroupFields[$i]['strGroupField'] == $this->fieldsArr[$j]['name']) {
                         $fieldIndex = GetFieldIndex($this->repGroupFields[$i]['strGroupField']);
                         if ($fieldIndex == $o[0]) {
                             $n = $this->repGroupFields[$i]['groupOrder'] - 1;
                             $this->_fields[$n]->_orderBy = $o[1];
                             $groupField = true;
                         }
                     }
                 }
             }
             //	don't add group fields to the $order_old
             if (!$groupField) {
                 $order_old[] = $o[2] . ' ' . $o[1];
             }
         }
         $this->_order_in = join(', ', $order_in);
         $this->_order_out = join(', ', $order_out);
         $this->_order_old = join(', ', $order_old);
     }
     for ($i = 0; $i < count($this->fieldsArr); $i++) {
         if ($this->fieldsArr[$i]['totalMax']) {
             $this->_aggregates[] = 'MAX(' . cached_ffn($this->fieldsArr[$i]['name']) . ') as ' . cached_ffn($this->fieldsArr[$i]['name'] . "MAX");
         }
         if ($this->fieldsArr[$i]['totalMin']) {
             $this->_aggregates[] = 'MIN(' . cached_ffn($this->fieldsArr[$i]['name']) . ') as ' . cached_ffn($this->fieldsArr[$i]['name'] . "MIN");
         }
         if ($this->fieldsArr[$i]['totalAvg']) {
             if (!IsDateFieldType(GetFieldType($this->fieldsArr[$i]['name'], $this->tName))) {
                 $this->_aggregates[] = 'AVG(' . cached_ffn($this->fieldsArr[$i]['name']) . ') as ' . cached_ffn($this->fieldsArr[$i]['name'] . "AVG");
                 $this->_aggregates[] = 'COUNT(' . cached_ffn($this->fieldsArr[$i]['name']) . ') as ' . cached_ffn($this->fieldsArr[$i]['name'] . "NAVG");
             }
         }
         if ($this->fieldsArr[$i]['totalSum']) {
             if (!IsDateFieldType(GetFieldType($this->fieldsArr[$i]['name'], $this->tName))) {
                 $this->_aggregates[] = 'SUM(' . cached_ffn($this->fieldsArr[$i]['name']) . ') as ' . cached_ffn($this->fieldsArr[$i]['name'] . "SUM");
             }
         }
     }
     $this->_reportSummary = $this->repPageSummary || $this->repGlobalSummary;
     $this->_pagesize = $pagesize;
 }
$FieldType = GetFieldType('title', 'stories_cat');
if ($FieldType != false) {
    if ($FieldType != 'varchar(40)') {
        echo "<font class=\"pn-normal\">Attempting to change datatype of 'title' in {$GLOBALS['prefix']}_stories_cat from {$FieldType} to varchar(40) ... ";
        if (!@mysql_query("ALTER TABLE {$GLOBALS['prefix']}_stories_cat modify title varchar(40) NOT NULL DEFAULT ''")) {
            echo "failed</font><br>\r\n";
        } else {
            echo "done!</font><br>\r\n";
        }
    } else {
        echo "<font class=\"pn-normal\">It appears 'title' in your {$GLOBALS['prefix']}_stories_cat table already has the correct definition ... skipping</font><br>\r\n";
    }
} else {
    echo "<font class=\"pn-normal\">There was an error when trying to determine what datatype 'title' in your {$GLOBALS['prefix']}_stories_cat table is ... <b>FAILED</b></font><br>";
}
$FieldType = GetFieldType('question', 'faqanswer');
if ($FieldType != false) {
    if ($FieldType != 'text') {
        echo "<font class=\"pn-normal\">Attempting to change datatype of 'question' in {$GLOBALS['prefix']}_faqanswer from {$FieldType} to text ... ";
        if (!@mysql_query("ALTER TABLE {$GLOBALS['prefix']}_faqanswer modify text DEFAULT NULL")) {
            echo "failed</font><br>\r\n";
        } else {
            echo "done!</font><br>\r\n";
        }
    } else {
        echo "<font class=\"pn-normal\">It appears 'question' in your {$GLOBALS['prefix']}_faqanswer table already has the correct definition ... skipping</font><br>\r\n";
    }
} else {
    echo "<font class=\"pn-normal\">There was an error when trying to determine what datatype 'question' in your {$GLOBALS['prefix']}_faqanswer table is ... <b>FAILED</b></font><br>";
}
/**
function ExportToExcel()
{
    global $rs, $nPageSize, $strTableName, $conn, $eventObj;
    if ($eventObj->exists("ListFetchArray")) {
        $row = $eventObj->ListFetchArray($rs);
    } else {
        $row = db_fetch_array($rs);
    }
    //	if(!$row)
    //		return;
    $arrLabel = array();
    $arrColumnWidth = array();
    $arrTotal = array();
    $arrTotalMessage = array();
    $totals = array();
    $arrFields = array();
    $arrTmpTotal = array();
    $arrFields = GetFieldsList($strTableName);
    $arrTmpTotal = GetTableData($strTableName, ".totalsFields", array());
    foreach ($arrFields as $value) {
        $arrLabel[$value] = label($value, $strTableName);
        $arrColumnWidth[$value] = 10;
        $totals[$value] = 0;
        $totalsType = "";
        foreach ($arrTmpTotal as $tvalue) {
            if ($tvalue["fName"] == $value) {
                $totalsType = $tvalue["totalsType"];
            }
        }
        $totalsFields[] = array('fName' => $value, 'totalsType' => $totalsType, 'viewFormat' => ViewFormat($value, $strTableName));
    }
    // write data rows
    $iNumberOfRows = 0;
    $objPHPExcel = ExportExcelInit($arrLabel, $arrColumnWidth);
    while ((!$nPageSize || $iNumberOfRows < $nPageSize) && $row) {
        countTotals($totals, $totalsFields, $row);
        $values = array();
        $arrData = array();
        $arrDataType = array();
        foreach ($arrFields as $value) {
            if (GetEditFormat($value, $strTableName) == EDIT_FORMAT_LOOKUP_WIZARD || GetEditFormat($value, $strTableName) == EDIT_FORMAT_RADIO) {
                $values[$value] = "";
                if (strlen($row[$value])) {
                    $values[$value] = DisplayLookupWizard($value, $row[$value], $row, "", MODE_EXPORT);
                }
            } elseif (IsBinaryType(GetFieldType($value, $strTableName))) {
                $values[$value] = $row[$value];
            } else {
                if (ViewFormat($value, $strTableName) != FORMAT_FILE_IMAGE && ViewFormat($value, $strTableName) != FORMAT_FILE && ViewFormat($value, $strTableName) != FORMAT_HYPERLINK && ViewFormat($value, $strTableName) != FORMAT_EMAILHYPERLINK && ViewFormat($value, $strTableName) != FORMAT_CHECKBOX) {
                    $format = ViewFormat($value, $strTableName);
                } else {
                    $format = FORMAT_NONE;
                }
                $values[$value] = GetData($row, $value, $format);
            }
        }
        $eventRes = true;
        if ($eventObj->exists('BeforeOut')) {
            $eventRes = $eventObj->BeforeOut($row, $values, $arrColumnWidth, $iNumberOfRows + 1, $objPHPExcel);
        }
        if ($eventRes) {
            $iNumberOfRows++;
            $i = 0;
            foreach ($arrFields as $value) {
                if (IsBinaryType(GetFieldType($value, $strTableName))) {
                    $arrDataType[$value] = "binary";
                } elseif (ViewFormat($value, $strTableName) == FORMAT_FILE_IMAGE) {
                    $arrDataType[$value] = "file";
                } elseif (ViewFormat($value, $strTableName) == FORMAT_DATE_SHORT || ViewFormat($value, $strTableName) == FORMAT_DATE_LONG || ViewFormat($value, $strTableName) == FORMAT_DATE_TIME) {
                    $arrDataType[$value] = "date";
                } else {
                    $arrDataType[$value] = "";
                }
                $arrData[$value] = $values[$value];
            }
            ExportExcelRecord($arrData, $arrDataType, $iNumberOfRows, $objPHPExcel);
        }
        if ($eventObj->exists("ListFetchArray")) {
            $row = $eventObj->ListFetchArray($rs);
        } else {
            $row = db_fetch_array($rs);
        }
    }
    if (count($arrTmpTotal)) {
        foreach ($arrFields as $fName) {
            $value = array();
            foreach ($arrTmpTotal as $tvalue) {
                if ($tvalue["fName"] == $fName) {
                    $value = $tvalue;
                }
            }
            $total = "";
            $totalMess = "";
            if ($value["totalsType"]) {
                if ($value["totalsType"] == "COUNT") {
                    $totalMess = "Count" . ": ";
                } elseif ($value["totalsType"] == "TOTAL") {
                    $totalMess = "Total" . ": ";
                } elseif ($value["totalsType"] == "AVERAGE") {
                    $totalMess = "Average" . ": ";
                }
                $total = GetTotals($fName, $totals[$fName], $value["totalsType"], $iNumberOfRows, $value["viewFormat"]);
            }
            $arrTotal[$fName] = $total;
            $arrTotalMessage[$fName] = $totalMess;
        }
    }
    ExportExcelTotals($arrTotal, $arrTotalMessage, ++$iNumberOfRows, $objPHPExcel);
    $formatExcel = "Excel2007";
    $extExcel = ".xlsx";
    if (@$_REQUEST["type"] == "excel5") {
        $formatExcel = "Excel5";
        $extExcel = ".xls";
    }
    ExportExcelSave(GoodFieldName($strTableName) . $extExcel, $formatExcel, $objPHPExcel);
}