Пример #1
0
/**
 * Create javascript to validate the data entered into a record.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 */
function get_validate_record_js()
{
    global $mod_strings;
    global $app_strings, $current_user;
    $lbl_last_name = $mod_strings['LBL_LIST_LAST_NAME'];
    $lbl_user_name = $mod_strings['LBL_LIST_USER_NAME'];
    $lbl_role_name = $mod_strings['LBL_ROLE_NAME'];
    $lbl_new_password = $mod_strings['LBL_LIST_PASSWORD'];
    $lbl_confirm_new_password = $mod_strings['LBL_LIST_CONFIRM_PASSWORD'];
    $lbl_user_email1 = $mod_strings['LBL_LIST_EMAIL'];
    $err_missing_required_fields = $app_strings['ERR_MISSING_REQUIRED_FIELDS'];
    $err_invalid_email_address = $app_strings['ERR_INVALID_EMAIL_ADDRESS'];
    $err_invalid_secondary_email_address = $app_strings['ERR_INVALID_SECONDARY_EMAIL_ADDRESS'];
    $lbl_user_image = $mod_strings['User Image'];
    $the_emailid = $app_strings['THE_EMAILID'];
    $email_field_is = $app_strings['EMAIL_FILED_IS'] . $err_invalid_email_address;
    $other_email_field_is = $app_strings['OTHER_EMAIL_FILED_IS'] . $err_invalid_email_address;
    $secondary_email_field_is = $app_strings['SECONDARY_EMAIL_FILED_IS'] . $err_invalid_secondary_email_address;
    $lbl_asterisk_details_not_set = $app_strings['LBL_ASTERISK_SET_ERROR'];
    //check asteriskdetails start
    $checkAsteriskDetails = checkAsteriskDetails();
    // Fix : 6362
    $record = $_REQUEST['record'] ? $_REQUEST['record'] : 'false';
    // used to check the asterisk extension in edit mode
    $mode = $_REQUEST['isDuplicate'] == 'true' ? 'true' : 'false';
    $extensions = getAsteriskExtensions();
    $extensions_list = Zend_Json::encode($extensions);
    //check asteriskdetails end
    $the_script = <<<EOQ

<script language="JavaScript" type="text/javascript" src="include/js/json.js"></script>
<script type="text/javascript" language="Javascript">
<!--  to hide script contents from old browsers
function set_fieldfocus(errorMessage,oMiss_field){
\t\talert("{$err_missing_required_fields}" + errorMessage);
\t\toMiss_field.focus();\t
}

function verify_data(form) {
        var isError = false;
\tvar errorMessage = "";
\t
\t//check if asterisk server details are set or not
\tif(trim(form.asterisk_extension.value)!="" && "{$checkAsteriskDetails}" == "false"){
\t\terrorMessage = "{$lbl_asterisk_details_not_set}";
\t\talert(errorMessage);
\t\treturn false;
\t}
\tvar extensions = {$extensions_list};
        if(form.asterisk_extension.value != "") {
            for(var userid in extensions){
                if(trim(form.asterisk_extension.value) == extensions[userid]) {
                    if(userid == {$record} && {$mode} == false) {
                    } else {
                        alert("This extension has already been configured for another user. Please use another extension.");
                        return false;
                    }
                }
            }
        }
\t//asterisk check ends
\t
\tif (trim(form.email1.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_user_email1}";
\t\toField_miss = form.email1;
\t}
\tif (trim(form.role_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_role_name}";
\t\toField_miss =form.role_name;
\t}
\tif (trim(form.last_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_last_name}";
\t\toField_miss =form.last_name;
\t}
\tif(form.mode.value !='edit')
\t{
\t\tif (trim(form.user_password.value) == "") {
\t\t\tisError = true;
\t\t\terrorMessage += "\\n{$lbl_new_password}";
\t\t\toField_miss =form.user_password;
\t\t}
\t\tif (trim(form.confirm_password.value) == "") {
\t\t\tisError = true;
\t\t\terrorMessage += "\\n{$lbl_confirm_new_password}";
\t\t\toField_miss =form.confirm_password;
\t\t}
\t}


\tif (trim(form.user_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_user_name}";
\t\toField_miss =form.user_name;
\t}

\tif (isError == true) {
\t\tset_fieldfocus(errorMessage,oField_miss);
\t\treturn false;
\t}
\tform.email1.value = trim(form.email1.value);
\tif (form.email1.value != "" && !/^[a-zA-Z0-9]+([!"#\$%&'()*+,./:;<=>?@\\^_`{|}~-]?[a-zA-Z0-9])*@[a-zA-Z0-9]+([\\_\\-\\.]?[a-zA-Z0-9]+)*\\.([\\-\\_]?[a-zA-Z0-9])+(\\.?[a-zA-Z0-9]+)?\$/.test(form.email1.value)) {
\t\talert("{$the_emailid}"+form.email1.value+"{$email_field_is}");
\t\tform.email1.focus();
\t\treturn false;
\t}
\tform.email2.value = trim(form.email2.value);
\tif (form.email2.value != "" && !/^[a-zA-Z0-9]+([!"#\$%&'()*+,./:;<=>?@\\^_`{|}~-]?[a-zA-Z0-9])*@[a-zA-Z0-9]+([\\_\\-\\.]?[a-zA-Z0-9]+)*\\.([\\-\\_]?[a-zA-Z0-9])+(\\.?[a-zA-Z0-9]+)?\$/.test(form.email2.value)) {
\t\talert("{$the_emailid}"+form.email2.value+"{$other_email_field_is}");
\t\tform.email2.focus();
\t\treturn false;
\t}
\tform.secondaryemail.value = trim(form.secondaryemail.value); 
\tif (form.secondaryemail.value != "" && !/^[a-zA-Z0-9]+([!"#\$%&'()*+,./:;<=>?@\\^_`{|}~-]?[a-zA-Z0-9])*@[a-zA-Z0-9]+([\\_\\-\\.]?[a-zA-Z0-9]+)*\\.([\\-\\_]?[a-zA-Z0-9])+(\\.?[a-zA-Z0-9]+)?\$/.test(form.secondaryemail.value)){
\t\talert("{$the_emailid}"+form.secondaryemail.value+"{$secondary_email_field_is}");
\t\tform.secondaryemail.focus();
\t\treturn false;
\t}



\tif(! upload_filter("imagename", "jpg|gif|bmp|png|JPG|GIF|BMP|PNG") )
\t{
\t\tform.imagename.focus();
\t\treturn false;
\t}


\tif(form.mode.value != 'edit')
\t{
\t\tif(trim(form.user_password.value) != trim(form.confirm_password.value))
\t\t{
\t\t\tset_fieldfocus("The password does't match",form.user_password);
\t\t\treturn false;
\t\t}
\t\tcheck_duplicate();
\t}else
\t{
\t//\t\$('user_status').disabled = false;
\t\tVtigerJS_DialogBox.block();
\t\tform.submit();
\t}
}

// end hiding contents from old browsers  -->
</script>

EOQ;
    return $the_script;
}
Пример #2
0
/**
 * Create javascript to validate the data entered into a record.
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
 * All Rights Reserved.
 * Contributor(s): ______________________________________..
 */
function get_validate_record_js()
{
    global $mod_strings;
    global $app_strings;
    $lbl_last_name = $mod_strings['LBL_LIST_LAST_NAME'];
    $lbl_user_name = $mod_strings['LBL_LIST_USER_NAME'];
    $lbl_role_name = $mod_strings['LBL_ROLE_NAME'];
    $lbl_new_password = $mod_strings['LBL_LIST_PASSWORD'];
    $lbl_confirm_new_password = $mod_strings['LBL_LIST_CONFIRM_PASSWORD'];
    $lbl_user_email1 = $mod_strings['LBL_LIST_EMAIL'];
    $err_missing_required_fields = $app_strings['ERR_MISSING_REQUIRED_FIELDS'];
    $err_invalid_email_address = $app_strings['ERR_INVALID_EMAIL_ADDRESS'];
    $err_invalid_yahoo_email_address = $app_strings['ERR_INVALID_YAHOO_EMAIL_ADDRESS'];
    $lbl_user_image = $mod_strings['User Image'];
    $the_emailid = $app_strings['THE_EMAILID'];
    $email_field_is = $app_strings['EMAIL_FILED_IS'] . $err_invalid_email_address;
    $other_email_field_is = $app_strings['OTHER_EMAIL_FILED_IS'] . $err_invalid_email_address;
    $yahoo_email_field_is = $app_strings['YAHOO_EMAIL_FILED_IS'] . $err_invalid_yahoo_email_address;
    $lbl_asterisk_details_not_set = $app_strings['LBL_ASTERISK_SET_ERROR'];
    //check asteriskdetails start
    $checkAsteriskDetails = checkAsteriskDetails();
    $extensions_list = implode(",", getAsteriskExtensions());
    //check asteriskdetails end
    $the_script = <<<EOQ

<script type="text/javascript" language="Javascript">
<!--  to hide script contents from old browsers
function set_fieldfocus(errorMessage,oMiss_field){
\t\talert("{$err_missing_required_fields}" + errorMessage);
\t\toMiss_field.focus();\t
}

function verify_data(form) {
\tvar existing_extensions = new Array({$extensions_list});
\tvar isError = false;
\tvar errorMessage = "";
\t
\t//check if asterisk server details are set or not
\tif(trim(form.asterisk_extension.value)!="" && "{$checkAsteriskDetails}" == "false"){
\t\terrorMessage = "{$lbl_asterisk_details_not_set}";
\t\talert(errorMessage);
\t\treturn false;
\t}

\tfor(var i=0; i<existing_extensions.length; i++){
\t\tif(form.asterisk_extension.value == existing_extensions[i]){
\t\t\talert("This extension has already been configured for another user. Please use another extension.");
\t\t\treturn false;
\t\t}
\t}
\t//asterisk check ends
\t
\tif (trim(form.email1.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_user_email1}";
\t\toField_miss = form.email1;
\t}
\tif (trim(form.role_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_role_name}";
\t\toField_miss =form.role_name;
\t}
\tif (trim(form.last_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_last_name}";
\t\toField_miss =form.last_name;
\t}
\tif(form.mode.value !='edit')
\t{
\t\tif (trim(form.user_password.value) == "") {
\t\t\tisError = true;
\t\t\terrorMessage += "\\n{$lbl_new_password}";
\t\t\toField_miss =form.user_password;
\t\t}
\t\tif (trim(form.confirm_password.value) == "") {
\t\t\tisError = true;
\t\t\terrorMessage += "\\n{$lbl_confirm_new_password}";
\t\t\toField_miss =form.confirm_password;
\t\t}
\t}


\tif (trim(form.user_name.value) == "") {
\t\tisError = true;
\t\terrorMessage += "\\n{$lbl_user_name}";
\t\toField_miss =form.user_name;
\t}

\tif (isError == true) {
\t\tset_fieldfocus(errorMessage,oField_miss);
\t\treturn false;
\t}
\tform.email1.value = trim(form.email1.value);
\tif (form.email1.value != "" && !/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,4})+\$/.test(form.email1.value)) {
\t\talert("{$the_emailid}"+form.email1.value+"{$email_field_is}");
\t\tform.email1.focus();
\t\treturn false;
\t}
\tform.email2.value = trim(form.email2.value);
\tif (form.email2.value != "" && !/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,4})+\$/.test(form.email2.value)) {
\t\talert("{$the_emailid}"+form.email2.value+"{$other_email_field_is}");
\t\tform.email2.focus();
\t\treturn false;
\t}
\tform.yahoo_id.value = trim(form.yahoo_id.value);
\tif (form.yahoo_id.value != "" && !/^\\w+([\\.-]?\\w+)*@\\w+([\\.-]?\\w+)*(\\.\\w{2,4})+\$/.test(form.yahoo_id.value) || (trim(form.yahoo_id.value) != "" && !(form.yahoo_id.value.indexOf('yahoo') > -1))) {
\t\talert("{$the_emailid}"+form.yahoo_id.value+"{$yahoo_email_field_is}");
\t\tform.yahoo_id.focus();
\t\treturn false;
\t}



\tif(! upload_filter("imagename", "jpg|gif|bmp|png|JPG|GIF|BMP|PNG") )
\t{
\t\tform.imagename.focus();
\t\treturn false;
\t}


\tif(form.mode.value != 'edit')
\t{
\t\tif(trim(form.user_password.value) != trim(form.confirm_password.value))
\t\t{
\t\t\tset_fieldfocus("The password does't match",form.user_password);
\t\t\treturn false;
\t\t}
\t\tcheck_duplicate();
\t}else
\t{
\t//\t\$('user_status').disabled = false;
\t\tVtigerJS_DialogBox.block();
\t\tform.submit();
\t}
}

// end hiding contents from old browsers  -->
</script>

EOQ;
    return $the_script;
}