/** Function to return the duplicate records data as a formatted array */ function getDuplicateRecordsArr($module) { global $adb, $app_strings, $list_max_entries_per_page, $theme; $field_values_array = getFieldValues($module); $field_values = $field_values_array['fieldnames_list']; $fld_arr = $field_values_array['fieldnames_array']; $col_arr = $field_values_array['columnnames_array']; $fld_labl_arr = $field_values_array['fieldlabels_array']; $ui_type = $field_values_array['fieldname_uitype']; $dup_query = getDuplicateQuery($module, $field_values, $ui_type); // added for page navigation $dup_count_query = substr($dup_query, stripos($dup_query, 'FROM'), strlen($dup_query)); $dup_count_query = "SELECT count(*) as count " . $dup_count_query; $count_res = $adb->query($dup_count_query); $no_of_rows = $adb->query_result($count_res, 0, "count"); if ($no_of_rows <= $list_max_entries_per_page) { $_SESSION['dup_nav_start' . $module] = 1; } else { if (isset($_REQUEST["start"]) && $_REQUEST["start"] != "" && $_SESSION['dup_nav_start' . $module] != $_REQUEST["start"]) { $_SESSION['dup_nav_start' . $module] = ListViewSession::getRequestStartPage(); } } $start = $_SESSION['dup_nav_start' . $module] != "" ? $_SESSION['dup_nav_start' . $module] : 1; $navigation_array = getNavigationValues($start, $no_of_rows, $list_max_entries_per_page); $start_rec = $navigation_array['start']; $end_rec = $navigation_array['end_val']; $navigationOutput = getTableHeaderNavigation($navigation_array, "", $module, "FindDuplicate", ""); if ($start_rec == 0) { $limit_start_rec = 0; } else { $limit_start_rec = $start_rec - 1; } $dup_query .= " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}"; //ends $nresult = $adb->query($dup_query); $no_rows = $adb->num_rows($nresult); require_once 'modules/Vtiger/layout_utils.php'; if ($no_rows == 0) { if ($_REQUEST['action'] == 'FindDuplicateRecords') { //echo "<br><br><center>".$app_strings['LBL_NO_DUPLICATE']." <a href='javascript:window.history.back()'>".$app_strings['LBL_GO_BACK'].".</a></center>"; //die; echo "<link rel='stylesheet' type='text/css' href='themes/{$theme}/style.css'>"; echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>"; echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>\n\n\t\t\t\t<table border='0' cellpadding='5' cellspacing='0' width='98%'>\n\t\t\t\t<tbody><tr>\n\t\t\t\t<td rowspan='2' width='11%'><img src='" . vtiger_imageurl('empty.jpg', $theme) . "' ></td>\n\t\t\t\t<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>{$app_strings['LBL_NO_DUPLICATE']}</span></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td class='small' align='right' nowrap='nowrap'>\n\t\t\t\t<a href='javascript:window.history.back();'>{$app_strings['LBL_GO_BACK']}</a><br> </td>\n\t\t\t\t</tr>\n\t\t\t\t</tbody></table>\n\t\t\t\t</div>"; echo "</td></tr></table>"; exit; } else { echo "<br><br><table align='center' class='reportCreateBottom big' width='95%'><tr><td align='center'>" . $app_strings['LBL_NO_DUPLICATE'] . "</td></tr></table>"; die; } } $rec_cnt = 0; $temp = array(); $sl_arr = array(); $grp = "group0"; $gcnt = 0; $ii = 0; //ii'th record in group while ($rec_cnt < $no_rows) { $result = $adb->fetchByAssoc($nresult); //echo '<pre>';print_r($result);echo '</pre>'; if ($rec_cnt != 0) { $sl_arr = array_slice($result, 2); array_walk($temp, 'lower_array'); array_walk($sl_arr, 'lower_array'); $arr_diff = array_diff($temp, $sl_arr); if (count($arr_diff) > 0) { $gcnt++; $temp = $sl_arr; $ii = 0; } $grp = "group" . $gcnt; } $fld_values[$grp][$ii]['recordid'] = $result['recordid']; for ($k = 0; $k < count($col_arr); $k++) { if ($rec_cnt == 0) { $temp[$fld_labl_arr[$k]] = $result[$col_arr[$k]]; } if ($ui_type[$fld_arr[$k]] == 56) { if ($result[$col_arr[$k]] == 0) { $result[$col_arr[$k]] = $app_strings['no']; } else { $result[$col_arr[$k]] = $app_strings['yes']; } } if ($ui_type[$fld_arr[$k]] == 75 || $ui_type[$fld_arr[$k]] == 81) { $vendor_id = $result[$col_arr[$k]]; if ($vendor_id != '') { $vendor_name = getVendorName($vendor_id); } $result[$col_arr[$k]] = $vendor_name; } if ($ui_type[$fld_arr[$k]] == 57) { $contact_id = $result[$col_arr[$k]]; if ($contact_id != '') { $parent_module = 'Contacts'; $displayValueArray = getEntityName($parent_module, $contact_id); if (!empty($displayValueArray)) { foreach ($displayValueArray as $key => $field_value) { $contactname = $field_value; } } } $result[$col_arr[$k]] = $contactname; } if ($ui_type[$fld_arr[$k]] == 15 || $ui_type[$fld_arr[$k]] == 16) { $result[$col_arr[$k]] = getTranslatedString($result[$col_arr[$k]], $module); } if ($ui_type[$fld_arr[$k]] == 33) { $fieldvalue = explode(' |##| ', $result[$col_arr[$k]]); $result[$col_arr[$k]] = array(); foreach ($fieldvalue as $picklistValue) { $result[$col_arr[$k]][] = getTranslatedString($picklistValue, $module); } $result[$col_arr[$k]] = implode(', ', $result[$col_arr[$k]]); } if ($ui_type[$fld_arr[$k]] == 68) { $parent_id = $result[$col_arr[$k]]; if ($parent_id != '') { $parentname = getParentName($parent_id); } $result[$col_arr[$k]] = $parentname; } if ($ui_type[$fld_arr[$k]] == 53 || $ui_type[$fld_arr[$k]] == 52) { if ($result[$col_arr[$k]] != '') { $owner = getOwnerName($result[$col_arr[$k]]); } $result[$col_arr[$k]] = $owner; } if ($ui_type[$fld_arr[$k]] == 50 or $ui_type[$fld_arr[$k]] == 51) { if ($module != 'Products') { $entity_name = getAccountName($result[$col_arr[$k]]); } else { $entity_name = getProductName($result[$col_arr[$k]]); } if ($entity_name != '') { $result[$col_arr[$k]] = $entity_name; } else { $result[$col_arr[$k]] = ''; } } if ($ui_type[$fld_arr[$k]] == 58) { $campaign_name = getCampaignName($result[$col_arr[$k]]); if ($campaign_name != '') { $result[$col_arr[$k]] = $campaign_name; } else { $result[$col_arr[$k]] = ''; } } if ($ui_type[$fld_arr[$k]] == 59) { $product_name = getProductName($result[$col_arr[$k]]); if ($product_name != '') { $result[$col_arr[$k]] = $product_name; } else { $result[$col_arr[$k]] = ''; } } /*uitype 10 handling*/ if ($ui_type[$fld_arr[$k]] == 10) { $result[$col_arr[$k]] = getRecordInfoFromID($result[$col_arr[$k]]); } if ($ui_type[$fld_arr[$k]] == 5 || $ui_type[$fld_arr[$k]] == 6 || $ui_type[$fld_arr[$k]] == 23) { if (${$result}[$col_arr[$k]] != '' && ${$result}[$col_arr[$k]] != '0000-00-00') { $date = new DateTimeField(${$result}[$col_arr[$k]]); $value = $date->getDisplayDate(); if (strpos(${$result}[$col_arr[$k]], ' ') > -1) { $value .= ' ' . $date->getDisplayTime(); } } elseif (${$result}[$col_arr[$k]] == '0000-00-00') { $value = ''; } else { $value = ${$result}[$col_arr[$k]]; } $result[$col_arr[$k]] = $value; } if ($ui_type[$fld_arr[$k]] == 71) { $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]]); } if ($ui_type[$fld_arr[$k]] == 72) { $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]], null, true); } $fld_values[$grp][$ii][$fld_labl_arr[$k]] = $result[$col_arr[$k]]; } $fld_values[$grp][$ii]['Entity Type'] = $result['deleted']; $ii++; $rec_cnt++; } $gro = "group"; for ($i = 0; $i < $no_rows; $i++) { $ii = 0; $dis_group[] = $fld_values[$gro . $i][$ii]; $count_group[$i] = count($fld_values[$gro . $i]); $ii++; $new_group[] = $dis_group[$i]; } $fld_nam = $new_group[0]; $ret_arr[0] = $fld_values; $ret_arr[1] = $fld_nam; $ret_arr[2] = $ui_type; $ret_arr["navigation"] = $navigationOutput; return $ret_arr; }
function getQueueMessage() { global $aPreValues; if ($_POST['msgs_id']) { $aSexValues = getFieldValues('Sex'); foreach ($aSexValues as $sKey => $sValue) { $aSexValues[$sKey] = _t($sValue); } $aAgeValues = array('all' => _t('_All'), 'selectively' => _t('_Selectively')); $aStartAgesOptions = array(); $aEndAgesOptions = array(); $gl_search_start_age = (int) getParam('search_start_age'); $gl_search_end_age = (int) getParam('search_end_age'); for ($i = $gl_search_start_age; $i <= $gl_search_end_age; $i++) { $aStartAgesOptions[$i] = $i; } for ($i = $gl_search_start_age; $i <= $gl_search_end_age; $i++) { $aEndAgesOptions[$i] = $i; } $aCountryOptions = array('all' => _t('_All')); foreach ($aPreValues['Country'] as $key => $value) { $aCountryOptions[$key] = _t($value['LKey']); } $aMembershipOptions = array('all' => _t('_All')); $memberships_arr = getMemberships(); foreach ($memberships_arr as $membershipID => $membershipName) { if ($membershipID == MEMBERSHIP_ID_NON_MEMBER) { continue; } $aMembershipOptions[$membershipID] = $membershipName; } $iRecipientMembers = (int) $GLOBALS['MySQL']->getOne("SELECT COUNT(`ID`) AS `count` FROM `Profiles` WHERE `Status`<>'Unconfirmed' AND `EmailNotify` = 1 LIMIT 1"); $aForm = array('form_attrs' => array('name' => 'form_queue', 'class' => 'form_queue_form', 'action' => $GLOBALS['site']['url_admin'] . 'notifies.php', 'method' => 'post'), 'inputs' => array('Send1' => array('type' => 'checkbox', 'name' => 'send_to_subscribers', 'label' => _t('_adm_mmail_Send_to_subscribers'), 'value' => 'non', 'checked' => true), 'Send2' => array('type' => 'checkbox', 'name' => 'send_to_members', 'label' => _t('_adm_mmail_Send_to_members'), 'value' => 'memb', 'checked' => true, 'attrs' => array('onClick' => 'setControlsState();'), 'info' => _t('_adm_mmail_Send_to_members_info', $iRecipientMembers)), 'sex' => array('type' => 'checkbox_set', 'name' => 'sex', 'values' => $aSexValues, 'value' => array_keys($aSexValues)), 'Age' => array('type' => 'select', 'name' => 'age', 'caption' => _t('_adm_mmail_Age'), 'value' => 'all', 'values' => $aAgeValues, 'attrs' => array('onClick' => 'setAgeState();')), 'StartAge' => array('type' => 'select', 'name' => 'age_start', 'caption' => _t('_from'), 'values' => $aStartAgesOptions, 'value' => $gl_search_start_age), 'EndAge' => array('type' => 'select', 'name' => 'age_end', 'caption' => _t('_to'), 'values' => $aEndAgesOptions, 'value' => $gl_search_end_age), 'Country' => array('type' => 'select', 'name' => 'country', 'caption' => _t('_Country'), 'values' => $aCountryOptions, 'value' => 'all'), 'Membership' => array('type' => 'select', 'name' => 'membership', 'caption' => _t('_adm_mmi_membership_levels'), 'values' => $aMembershipOptions, 'value' => 'all'), 'msgs_id' => array('type' => 'hidden', 'name' => 'msgs_id', 'value' => (int) $_POST['msgs_id']), 'submit' => array('type' => 'submit', 'name' => 'queue_message', 'value' => _t('_Submit')))); $oForm = new BxTemplFormView($aForm); $sTmplResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('notifies_filter.html', array()); return DesignBoxContent(_t('_adm_mmail_Queue_message'), $oForm->getCode() . $sTmplResult, 11); } }
/** * return code for "SELECT" html element * $fieldname - field name for wich will be retrived values * $default - default value to be selected, if empty then default value will be retrived from database **/ function SelectOptions($sField, $sDefault = '', $sUseLKey = 'LKey') { $aValues = getFieldValues($sField, $sUseLKey); $sRet = ''; foreach ($aValues as $sKey => $sValue) { $sStr = _t($sValue); $sSelected = $sKey == $sDefault ? 'selected="selected"' : ''; $sRet .= "<option value=\"{$sKey}\" {$sSelected}>{$sStr}</option>\n"; } return $sRet; }
function get_where_clause($module, $column_fields) { global $current_user, $dup_ow_count, $adb; $where_clause = ""; $field_values_array = getFieldValues($module); $field_values = $field_values_array['fieldnames_list']; $tblname_field_arr = explode(",", $field_values); $uitype_arr = $field_values_array['fieldname_uitype']; $focus = CRMEntity::getInstance($module); foreach ($tblname_field_arr as $val) { list($tbl, $col, $fld) = explode(".", $val); $col_name = $tbl . "." . $col; $field_value = $column_fields[$fld]; if ($fld == $focus->table_index && $column_fields[$focus->table_index] != '' && !is_integer($column_fields[$focus->table_index])) { $field_value = getEntityId($module, $column_fields[$focus->table_index]); } if (is_uitype($uitype_arr[$fld], '_users_list_') && $field_value == '') { $field_value = $current_user->id; } $where_clause .= " AND ifnull(" . $adb->sql_escape_string($col_name) . ",'') = ifnull('" . $adb->sql_escape_string($field_value) . "','') "; } return $where_clause; }
function PageCodeSearchForm() { global $oPF; global $sPageHeader; global $sSearchMode; ob_start(); ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF']; ?> "> <table class="search_form" cellspacing="0"> <?php foreach ($oPF->aBlocks as $aBlock) { ?> <tr class="search_form_block"> <th colspan="2"><?php echo _t($aBlock['Caption']); ?> </th> </tr> <?php foreach ($aBlock['Items'] as $aItem) { ?> <tr class="search_form_row"> <td class="search_form_caption"><?php echo _t($aItem['Caption']); ?> :</td> <td class="search_form_value"> <?php //draw the control switch ($aItem['Type']) { case 'text': case 'area': ?> <input type="text" name="<?php echo $aItem['Name']; ?> " class="input_text" /> <?php break; case 'date': case 'range': case 'num': echo _t('_From'); ?> <input type="text" name="<?php echo $aItem['Name']; ?> [0]" class="input_date" /> <?php echo _t('_To'); ?> <input type="text" name="<?php echo $aItem['Name']; ?> [1]" class="input_date" /> <?php break; case 'select_one': case 'select_set': switch ($aItem['Control']) { case 'select': ?> <select name="<?php echo $aItem['Name']; ?> []" multiple="multiple" class="input_select"> <?php echo SelectOptions($aItem['Name']); ?> </select> <?php break; case 'radio': case 'checkbox': $aValues = getFieldValues($aItem['Name']); foreach ($aValues as $sKey => $sValue) { ?> <input type="checkbox" name="<?php echo $aItem['Name']; ?> []" value="<?php echo $sKey; ?> " id="<?php echo $aItem['Name']; ?> _<?php echo $sKey; ?> " /> <label for="<?php echo $aItem['Name']; ?> _<?php echo $sKey; ?> "><?php echo _t($sValue); ?> </label> <?php } break; } break; case 'bool': ?> <input type="checkbox" name="<?php $aItem['Name']; ?> " value="1" /> <?php break; case 'system': switch ($aItem['Name']) { case 'Couple': ?> <input type="checkbox" name="Couple[0]" value="1" id="Couple_0" /> <label for="Couple_0"><?php echo _t('_Single'); ?> </label> <input type="checkbox" name="Couple[1]" value="1" id="Couple_1" /> <label for="Couple_1"><?php echo _t('_Couple'); ?> </label> <?php break; case 'Keyword': ?> <input type="text" name="<?php echo $aItem['Name']; ?> " class="input_text" /> <?php break; case 'Location': echo 'Not implemented yet'; $sLivingWithinC = _t("_living within"); $sMilesC = _t("_miles"); $sKmC = _t("_kilometers"); $sFromZipC = _t("_from zip/postal code"); $sRet = <<<EOF <table class=small cellspacing=3 cellpadding=0 border="0"> <tr> <td> \t {$sLivingWithinC} <input class=no type=text name="distance" size=12 /> <select name="metric"> \t<option selected="selected" value="miles">{$sMilesC}</option> \t<option value="km">{$sKmC}</option> </select> \t {$sFromZipC} <input class=no type=text name=zip size=12 /> </td> </tr> </table> EOF; echo $sRet; break; } break; } ?> </td> </tr> <?php } } ?> <tr> <td class="search_form_submit_row" colspan="2"> <input type="checkbox" name="online_only" id="online_only" /> <label for="online_only"><?php echo _t('_online only'); ?> </label> <input type="checkbox" name="photos_only" id="photos_only" /> <label for="photos_only"><?php echo _t('_With photos only'); ?> </label> <input type="submit" value="<?php echo _t('_Fetch'); ?> " /> </td> </tr> </table> </form> <?php echo DesignBoxContentBorder($sPageHeader, ob_get_clean()); }
function QueueMessage() { $msg_id = (int) $_POST['msgs_id']; $ret = ""; $query = "SELECT `ID` FROM `NotifyMsgs` WHERE `ID` = {$msg_id}"; $arr_arr = db_arr($query); if (!$arr_arr) { return "Failed to queue emails (ID: {$msg_id})."; } // Initially no emails queued $emails = 0; // Send to all emails in NotifyEmails table if ($_POST['send_to_subscribers'] == 'on') { $res_eml = db_res("SELECT `ID` FROM `NotifyEmails`"); while ($arr_eml = mysql_fetch_array($res_eml)) { $res = db_res("SELECT `NotifyEmails`.`Email` FROM `NotifyQueue` INNER JOIN `NotifyEmails` ON (`NotifyQueue`.`Email` = `NotifyEmails`.`ID`) WHERE `NotifyQueue`.`Email` = {$arr_eml['ID']} AND `NotifyQueue`.`Msg` = {$msg_id} AND `From` = 'NotifyEmails'"); if ($res && ($arr = mysql_fetch_array($res))) { $ret .= "Email(notify) <b><u>{$arr['Email']}</u></b> already exists in queue.<br>"; continue; } $res = db_res("INSERT INTO `NotifyQueue` SET `Email` = {$arr_eml['ID']}, `Msg` = {$msg_id}, `From` = 'NotifyEmails', `Creation` = NOW()"); if (!$res) { $ret .= "Email <b><u>{$arr['Email']}</u></b> was not added to queue.<br>"; continue; } $emails++; } } // Send to all profiles if ($_POST['send_to_members'] == 'on') { // Sex filter $apply_filter = false; $vals = getFieldValues('Sex'); foreach ($vals as $v) { if (!isset($_POST["sex_{$v}"]) || $_POST["sex_{$v}"] != 'on') { $apply_filter = true; break; } } if ($apply_filter) { $sex_string_buffer = "'-1'"; foreach ($vals as $v => $lang_val) { if (isset($_POST["sex_{$v}"]) && $_POST["sex_{$v}"] == 'on') { $sex_string_buffer .= ",'{$v}'"; } } } else { $sex_filter_sql = ''; } // Age filter $age_start = (int) $_POST['age_start']; $age_end = (int) $_POST['age_end']; if ($age_start && $age_end) { $date_start = (int) (date("Y") - $age_start); $date_end = (int) (date("Y") - $age_end - 1); $date_start = $date_start . date("-m-d"); $date_end = $date_end . date("-m-d"); $age_filter_sql = "AND (TO_DAYS(`DateOfBirth`) BETWEEN TO_DAYS('{$date_end}') AND (TO_DAYS('{$date_start}')+1))"; } else { $age_filter_sql = ''; } // Country filter if ($_POST['country'] != 'all') { $country = process_db_input($_POST['country']); $country_filter_sql = "AND `Country` = '{$country}'"; } else { $country_filter_sql = ''; } // Membership filter if ($_POST['membership'] != 'all') { $membershipID = (int) $_POST['membership']; } else { $membershipID = -1; } $res_eml = db_res("SELECT `ID` FROM `Profiles` WHERE `Status` <> 'Unconfirmed' AND `EmailNotify` = 'NotifyMe' {$sex_filter_sql} {$age_filter_sql} {$country_filter_sql}"); while ($arr_eml = mysql_fetch_array($res_eml)) { // Dynamic membership filter $membership_info = getMemberMembershipInfo($arr_eml['ID']); if ($membershipID != -1 && $membership_info['ID'] != $membershipID) { continue; } $res = db_res("SELECT `Profiles`.`Email` FROM `NotifyQueue` INNER JOIN `Profiles` ON (`NotifyQueue`.`Email` = `Profiles`.`ID`) WHERE `NotifyQueue`.`Email` = {$arr_eml['ID']} AND `NotifyQueue`.`Msg` = {$msg_id} AND `From` = 'Profiles' "); if ($res && ($arr = mysql_fetch_array($res))) { $ret .= "Email(profiles) <b><u>{$arr['Email']}</u></b> already exists in queue.<br>"; continue; } $res = db_res("INSERT INTO `NotifyQueue` SET `Email` = {$arr_eml['ID']}, `Msg` = {$msg_id}, `From` = 'Profiles', `Creation` = NOW()"); if (!$res) { $ret .= "Email <b><u>{$arr['Email']}</u></b> was not added to queue.<br>"; continue; } $emails++; } } $ret .= (int) $emails . " emails was successfully added to queue."; return $ret; }
function makeList($name, $digit_range, $sField, $selected = '', $js = '') { $ret = ''; $ret .= "<select id=\"{$name}\" name=\"{$name}\" {$js}>"; if ($digit_range) { list($a, $b) = preg_split("/[\\.,\\-]/", $digit_range); for ($i = $a; $i <= $b; $i++) { if ($selected && $selected == $i) { $sel = "selected=\"selected\""; } else { $sel = ''; } $ret .= "<option value=\"{$i}\" {$sel}>{$i}</option>"; } } elseif ($sField) { $arr = getFieldValues($sField); $arr = array_merge(array('all' => '__All'), $arr); foreach ($arr as $key => $value) { if ($selected == $key) { $sel = "selected=\"selected\""; } else { $sel = ''; } $ret .= "<option value=\"{$key}\" {$sel}>" . _t($value) . "</option>"; } } else { return false; } $ret .= '</select>'; return $ret; }