Esempio n. 1
0
    /**
     *	Draws mass mail form
     *		$param $draw
     */
    public function DrawMassMailForm($draw = true)
    {
        global $objSettings;
        $template_subject = '';
        $template_content = '';
        $result = database_query('SELECT COUNT(*) as cnt FROM ' . $this->TABLE_NAME . ' WHERE is_active = 1 AND email_notifications = 1 AND email != \'\'', DATA_ONLY, FIRST_ROW_ONLY);
        $members_emails_count = isset($result['cnt']) ? $result['cnt'] : 0;
        $result = database_query('SELECT COUNT(*) as cnt FROM ' . TABLE_ACCOUNTS . ' WHERE is_active = 1 AND email != \'\'', DATA_ONLY, FIRST_ROW_ONLY);
        $admins_emails_count = isset($result['cnt']) ? $result['cnt'] : 0;
        $emails_count = $members_emails_count + $admins_emails_count;
        $result = database_query('SELECT COUNT(*) as cnt FROM ' . TABLE_NEWS_SUBSCRIBED . ' WHERE email != \'\'', DATA_ONLY, FIRST_ROW_ONLY);
        $newsletter_subscribers_count = isset($result['cnt']) ? $result['cnt'] : 0;
        $send_copy_to_admin = '1';
        $email_from = $objSettings->GetParameter('admin_email');
        $template_code = isset($_GET['template_code']) ? prepare_input($_GET['template_code']) : '';
        $duration = isset($_POST['duration']) ? (int) $_POST['duration'] : '5';
        $members_module_installed = Modules::IsModuleInstalled($this->MODULE_NAME);
        // load appropriate email template
        if ($template_code != '') {
            $template = $this->GetTemplate($template_code, Application::Get('lang'));
            $template_subject = $template['template_subject'];
            $template_content = $template['template_content'];
        }
        if ($this->error == true) {
            $template_code = isset($_POST['template_name']) ? prepare_input($_POST['template_name']) : '';
            $template_subject = isset($_POST['subject']) ? prepare_input($_POST['subject']) : '';
            $template_content = isset($_POST['message']) ? prepare_input($_POST['message']) : '';
        }
        $output = '<script type="text/javascript">
			function duration_OnChange(val){
				var el_package_size = (document.getElementById(\'package_size\')) ? document.getElementById(\'package_size\') : null;
				if(val == \'\' && el_package_size){
					el_package_size.selectedIndex = 0;
					el_package_size.disabled = \'disabled\';
				}else{
					el_package_size.disabled = \'\';
				}
			}
			
			function email_to_OnChange(val){
				var el_send_copy_to_admin = (document.getElementById(\'send_copy_to_admin\')) ? document.getElementById(\'send_copy_to_admin\') : null;
				if(val == \'admins\' && el_send_copy_to_admin){
					el_send_copy_to_admin.disabled = \'disabled\';
				}else{
					el_send_copy_to_admin.disabled = \'\';
				}
			}
					
			function OnSubmit_Check(){
				var email_to = (document.getElementById(\'email_to\')) ? document.getElementById(\'email_to\').value : \'\';
				var email_from = (document.getElementById(\'email_from\')) ? document.getElementById(\'email_from\').value : \'\';
				var subject = (document.getElementById(\'subject\')) ? document.getElementById(\'subject\').value : \'\';
				var message = (document.getElementById(\'message\')) ? document.getElementById(\'message\').value : \'\';
				if(email_to == \'\'){
					alert(\'' . str_replace('_FIELD_', _EMAIL_TO, _FIELD_CANNOT_BE_EMPTY) . '\');
					document.getElementById(\'email_to\').focus();
					return false;            
				}else if(email_from == \'\'){
					alert(\'' . str_replace('_FIELD_', _EMAIL_FROM, _FIELD_CANNOT_BE_EMPTY) . '\');
					document.getElementById(\'email_from\').focus();
					return false;
				}else if(email_from != \'\' && !appIsEmail(email_from)){
					alert(\'' . str_replace('_FIELD_', _EMAIL_FROM, _FIELD_MUST_BE_EMAIL) . '\');
					document.getElementById(\'email_from\').focus();
					return false;			
				}else if(subject == \'\'){
					alert(\'' . str_replace('_FIELD_', _SUBJECT, _FIELD_CANNOT_BE_EMPTY) . '\');
					document.getElementById(\'subject\').focus();
					return false;
				}else if(message == \'\'){
					alert(\'' . str_replace('_FIELD_', _MESSAGE, _FIELD_CANNOT_BE_EMPTY) . '\');
					document.getElementById(\'message\').focus();
					return false;
				}else if(email_to == \'all\'){
					if(!confirm(\'' . _PERFORM_OPERATION_COMMON_ALERT . '\')){
						return false;
					}
				}
				return true;
			}
		</script>';
        $output .= '<form action="index.php?admin=mass_mail" method="post" style="margin:0px;">
			' . draw_hidden_field('task', 'send', false) . '
			' . draw_hidden_field('email_random_code', get_random_string(10), false) . '
			' . draw_token_field(false) . '
			
			<table border="0" cellspacing="10">
			<tr>
				<td align="left" valign="top">
					<fieldset style="height:410px;">
					<legend><b>' . _FORM . ':</b></legend>
					<table width="97%" align="center" border="0" cellspacing="5">
					<tr>
						<td align="right" nowrap="nowrap">
							<label>' . _EMAIL_TEMPLATES . ':</label><br>
							' . prepare_permanent_link('index.php?admin=email_templates', '[ ' . _MANAGE_TEMPLATES . ' ]', '', '') . '
						</td>
						<td></td>
						<td>
							<table cellpadding="0" cellspacing="0">
							<tr valign="middle">
								<td>
									<select name="template_name" id="template_name" style="margin-bottom:3px;" onchange="javascript:appGoTo(\'admin=mass_mail&template_code=\'+this.value)">
										<option value="">-- ' . _NO_TEMPLATE . ' --</option>';
        $templates = $this->GetAllTemplates('is_system_template=0');
        for ($i = 0; $i < $templates[1]; $i++) {
            $output .= '<option';
            $output .= $templates[0][$i]['is_system_template'] == '1' ? ' style="background-color:#ffffcc;color:#000055"' : '';
            $output .= $template_code == $templates[0][$i]['template_code'] ? ' selected="selected"' : '';
            $output .= ' value="' . encode_text($templates[0][$i]['template_code']) . '">' . $templates[0][$i]['template_name'] . '</option>';
        }
        $output .= '
									</select>						
								</td>
							</tr>
							</table>                    
						</td>
					</tr>
					<tr>
						<td align="right" nowrap="nowrap"><label>' . _EMAIL_TO . ':</label></td>
						<td><span class="mandatory_star">*</span></td>
						<td>
							<select name="email_to" id="email_to" style="margin-bottom:3px;" onchange="email_to_OnChange(this.value)">
								<option value="">-- ' . _SELECT . ' --</option>
								<option value="test" style="background-color:#ffffcc;color:#000055">' . _TEST_EMAIL . ' (' . $email_from . ')</option>';
        if (Modules::IsModuleInstalled('news')) {
            $output .= '<option value="newsletter_subscribers" style="background-color:#ffccff;color:#000055">' . _NEWSLETTER_SUBSCRIBERS . ' (' . $newsletter_subscribers_count . ')</option>';
        }
        if ($members_module_installed) {
            $output .= '<optgroup label="' . $this->MEMBERS_NAME . '">';
            $output .= '<option value="members|all">' . _ALL . ' (' . $members_emails_count . ')</option>';
            if (self::$PROJECT == 'ShoppingCart' || self::$PROJECT == 'BusinessDirectory' || self::$PROJECT == 'HotelSite') {
                $arrMembersGroups = CustomerGroups::GetAllGroupsByCustomers();
            } else {
                if (self::$PROJECT == 'MedicalAppointment') {
                    $arrMembersGroups = PatientGroups::GetAllGroupsByPatiens();
                } else {
                    $arrMembersGroups = UserGroups::GetAllGroupsByUsers();
                }
            }
            $member_groups_emails_count = 0;
            if ($arrMembersGroups[1] > 0) {
                foreach ($arrMembersGroups[0] as $key => $val) {
                    if ($val[$this->MODULE_NAME . '_count']) {
                        $output .= '<option value="members|' . $val['id'] . '">' . $val['name'] . ' (' . $val[$this->MODULE_NAME . '_count'] . ')</option>';
                        $member_groups_emails_count += $val[$this->MODULE_NAME . '_count'];
                    }
                }
            }
            $member_non_groups_emails = $members_emails_count - $member_groups_emails_count;
            $output .= '<option value="members|uncategorized">' . _UNCATEGORIZED . ' (' . $member_non_groups_emails . ')</option>';
            $output .= '</optgroup>';
        }
        $output .= '<option value="admins">' . _ADMINS . ' (' . $admins_emails_count . ')</option>';
        if ($members_module_installed) {
            $output .= '<option value="all">' . $this->ADMINS_MEMBERS_NAME . ' (' . $emails_count . ')</option>';
        }
        $output .= '</select>
						</td>
					</tr>            
					<tr>
						<td align="right" nowrap="nowrap"><label for="email">' . _EMAIL_FROM . ':</label></td>
						<td><span class="mandatory_star">*</span></td>
						<td>
							<input type="text" name="email_from" style="width:210px" id="email_from" value="' . decode_text($email_from) . '" maxlength="70" />
						</td>
					</tr>
					<tr valign="top">
						<td align="right" nowrap="nowrap"><label>' . _SUBJECT . ':</label></td>
						<td><span class="mandatory_star">*</span></td>
						<td>
							<input type="text" style="width:410px" name="subject" id="subject" value="' . decode_text($template_subject) . '" maxlength="255" />
						</td>
					</tr>
					<tr valign="top">
						<td align="right" nowrap="nowrap"><label>' . _MESSAGE . ':</label></td>
						<td><span class="mandatory_star">*</span></td>
						<td>
							<textarea style="width:465px;margin-right:10px;" rows="10" name="message" id="message">' . $template_content . '</textarea>
						</td>
					</tr>';
        $output .= '<tr valign="middle">
						<td colspan="2"></td>
						<td><img src="images/question_mark.png" alt="">' . _MASS_MAIL_ALERT . '</td>
					</tr>';
        $output .= '<tr><td colspan="3" nowrap style="height:6px;"></td></tr>
					<tr>
						<td align="right" nowrap="nowrap"><a href="javascript:void(0);" onclick="appPopupWindow(\'mail_preview.html\',\'message\')">[ ' . _PREVIEW . ' ]</a></td>
						<td></td>
						<td>
							<div style="float:left"><input type="checkbox" class="form_checkbox" name="send_copy_to_admin" id="send_copy_to_admin" ' . ($send_copy_to_admin == '1' ? 'checked="checked"' : '') . ' value="1"> <label for="send_copy_to_admin">' . _SEND_COPY_TO_ADMIN . '</label></div>
							<div style="float:right"><input class="form_button" type="submit" name="btnSubmit" value="' . _SEND . '" onclick="return OnSubmit_Check();">&nbsp;&nbsp;</div>
						</td>
					</tr>
					</table>
					</fieldset>
				</td>        
				<td align="left" valign="top">
					<fieldset style="padding-' . Application::Get('defined_right') . ':10px;">
					<legend>' . _PREDEFINED_CONSTANTS . ':</legend>
					<ul>
						<li>{FIRST NAME} <br><span style="color:a0a0a0">' . _PC_FIRST_NAME_TEXT . '</span></li>
						<li>{LAST NAME} <br><span style="color:a0a0a0">' . _PC_LAST_NAME_TEXT . '</span></li>
						<li>{USER NAME} <br><span style="color:a0a0a0">' . _PC_USER_NAME_TEXT . '</span></li>
						<li>{USER EMAIL} <br><span style="color:a0a0a0">' . _PC_USER_EMAIL_TEXT . '</span></li>
						<li>{BASE URL} <br><span style="color:a0a0a0">' . _PC_WEB_SITE_BASED_URL_TEXT . '</span></li>
						<li>{WEB SITE} <br><span style="color:a0a0a0">' . _PC_WEB_SITE_URL_TEXT . '</span></li>
						<li>{YEAR} <br><span style="color:a0a0a0">' . _PC_YEAR_TEXT . '</span></li>
					</ul>
					</fieldset>
				</td>
			</tr>
			</table>    
		</form>';
        if ($draw) {
            echo $output;
        } else {
            return $output;
        }
    }