function show_report_LO($report_data = NULL, $other = '')
 {
     $jump_url = '';
     //show_report
     checkPerm('view');
     $lang =& DoceboLanguage::createInstance('report', 'framework');
     if (isset($_POST['send_mail_confirm'])) {
         $op = 'send_mail_confirm';
     } elseif (isset($_POST['send_mail'])) {
         $op = 'send_mail';
     } else {
         $op = 'show_result';
     }
     switch ($op) {
         case 'send_mail_confirm':
             $subject = importVar('mail_object', false, '[' . $lang->def('_SUBJECT') . ']');
             //'[No subject]');
             $body = importVar('mail_body', false, '');
             $acl_man = new DoceboACLManager();
             $user_info = $acl_man->getUser(getLogUserId(), false);
             if ($user_info) {
                 $sender = $user_info[ACL_INFO_EMAIL];
             }
             $mail_recipients = unserialize(urldecode(Get::req('mail_recipients', DOTY_STRING, '')));
             // prepare intestation for email
             $from = "From: " . $sender . $GLOBALS['mail_br'];
             $header = "MIME-Version: 1.0" . $GLOBALS['mail_br'] . "Content-type: text/html; charset=" . getUnicode() . $GLOBALS['mail_br'];
             $header .= "Return-Path: " . Get::sett('sender_event') . $GLOBALS['mail_br'];
             $header .= "Reply-To: " . Get::sett('sender_event') . $GLOBALS['mail_br'];
             $header .= "X-Sender: " . Get::sett('sender_event') . $GLOBALS['mail_br'];
             $header .= "X-Mailer: PHP/" . phpversion() . $GLOBALS['mail_br'];
             // send mail
             $arr_recipients = array();
             foreach ($mail_recipients as $recipient) {
                 $rec_data = $acl_man->getUser($recipient, false);
                 //mail($rec_data[ACL_INFO_EMAIL] , stripslashes($subject), stripslashes(nl2br($body)), $from.$header."\r\n");
                 $arr_recipients[] = $rec_data[ACL_INFO_EMAIL];
             }
             $mailer = DoceboMailer::getInstance();
             $mailer->SendMail($sender, $arr_recipients, stripslashes($subject), stripslashes(nl2br($body)));
             $result = getResultUi($lang->def('_OPERATION_SUCCESSFUL'));
             cout($this->_get_LO_query('html', NULL, $result));
             break;
         case 'send_mail':
             require_once _base_ . '/lib/lib.form.php';
             $mail_recipients = Get::req('mail_recipients', DOTY_MIXED, array());
             cout('' . Form::openElementSpace() . Form::getTextfield($lang->def('_SUBJECT'), 'mail_object', 'mail_object', 255) . Form::getTextarea($lang->def('_MAIL_BODY'), 'mail_body', 'mail_body') . Form::getHidden('mail_recipients', 'mail_recipients', urlencode(serialize($mail_recipients))) . Form::closeElementSpace() . Form::openButtonSpace() . Form::getButton('send_mail_confirm', 'send_mail_confirm', $lang->def('_SEND_MAIL')) . Form::getButton('undo_mail', 'undo_mail', $lang->def('_UNDO')) . Form::closeButtonSpace() . '</div>', 'content');
             break;
         default:
             cout($this->_get_LO_query('html', $report_data, $other));
     }
 }
function sendMessages($result)
{
    $start_time = date(TIME_FORMAT);
    $api_class = new api_class();
    $api_class->mobile = $_REQUEST['mobile'];
    $api_class->username = $_REQUEST['username'];
    $api_class->password = $_REQUEST['password'];
    $api_class->api_id = $_REQUEST['api_id'];
    $api_class->text = $_REQUEST['text'];
    //先根据短信内容计算credit.
    if ($api_class->text != "") {
        //根据短信内容计算花费的credit.
        $api_class->cost = countCharacters($api_class->text);
        if (preg_match('/[\\x80-\\xff]./', $api_class->text)) {
            //中文,全部专程unicode码
            $api_class->text = getUnicode($api_class->text);
            $unicode = 1;
        } else {
            //是英文的话再把空格转换下.
            $api_class->text = str_replace(' ', '%20', $_REQUEST['text']);
            $message->message_content = ereg_replace(Chr(10), '%0A', $message->message_content);
            $message->message_content = ereg_replace(Chr(13), '', $message->message_content);
        }
    }
    $api = $api_class->checkAPI();
    if (!$api) {
        $result["status"] = "fail";
        $result["message"] = "params error";
    } else {
        $mobile_arr = explode(",", $api_class->mobile);
        //print_r($mobile_arr);
        if ($api->balance < count($mobile_arr) * $api_class->cost) {
            $result["status"] = "fail";
            $result["message"] = "no enough bulance";
        } else {
            $success_list = "";
            //成功列表
            $fail_list = "";
            //失败列表
            $success_count = 0;
            //成功发送次数
            $fail_count = 0;
            //失败发送次数
            //循环发送短信
            for ($i = 0; $i < count($mobile_arr); $i++) {
                if ($mobile_arr[$i] == "") {
                    continue;
                }
                $mobile_arr[$i] = formatMobile($mobile_arr[$i]);
                $url = "http://api.clickatell.com/http/sendmsg?user="******"&password="******"&api_id=" . $api->api_id . "&to=" . $mobile_arr[$i] . "&text=" . $api_class->text . "&concat=" . $api_class->cost;
                if ($api->api_type == 1) {
                    $url .= "&from=" . $api->sender_name;
                }
                //如果短信内容包含中文,需要加unicode=1
                if ($unicode == 1) {
                    $url .= "&unicode=1";
                }
                //echo $url . "<br />";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                $content = curl_exec($ch);
                curl_close($ch);
                //判断返回的内容是否包含ID
                if (strpos($content, "ID:") !== false) {
                    //发送成功
                    if ($success_count == 0) {
                        $success_list = "[" . $mobile_arr[$i] . "]";
                    } else {
                        $success_list .= ",[" . $mobile_arr[$i] . "]";
                    }
                    $success_count++;
                } else {
                    //发送失败
                    $message->sms_record_remark = $content;
                    if ($fail_count == 0) {
                        $fail_list = "[" . $mobile_arr[$i] . "]";
                    } else {
                        $fail_list .= ",[" . $mobile_arr[$i] . "]";
                    }
                    $fail_count++;
                }
            }
            $message = new message();
            $message->api_id = $api->api_id;
            $message->sms_record_time = date(TIME_FORMAT);
            $message->sms_success_list = $success_list;
            $message->sms_fail_list = $fail_list;
            $message->sms_success_count = $success_count;
            $message->sms_fail_count = $fail_count;
            $message->sms_content = $api_class->text;
            $message->user_id = $api->user_id;
            $message->company_id = $api->company_id;
            $message->department_id = $api->department_id;
            $end_time = date(TIME_FORMAT);
            $message->sms_record_remark .= "start at " . $start_time . "; end at " . $end_time;
            $company = new company();
            $company->company_id = $api->company_id;
            $company->deductBalance($message->sms_success_count * $api_class->cost);
            $message->sendMessage();
            $result["status"] = "success";
            $result["message"] = "success:" . $success_count . ",fail:" . $fail_count;
        }
    }
    return $result;
}
Beispiel #3
0
/**
 * 短信发送
 */
function add()
{
    $start_time = date(TIME_FORMAT);
    $message = getField();
    //根据获取的短信内容和联系人列表,发送短信
    if ($message->message_content == "" || trim($message->message_content) == "") {
        header("location:message.php?method=addForward&error=6");
        return;
    } else {
        //根据短信内容计算花费的credit.
        $message->cost = countCharacters($message->message_content);
        if (preg_match('/[\\x80-\\xff]./', $_POST['message_content'])) {
            //中文,全部专程unicode码
            $message->message_content = $_POST['message_content'];
            $message->message_content = getUnicode($message->message_content);
            $unicode = 1;
        } else {
            //是英文的话再把空格转换下.
            $message->message_content = $_POST['message_content'];
            $message->message_content = str_replace(' ', '%20', $message->message_content);
            @($message->message_content = ereg_replace(Chr(10), '%0A', $message->message_content));
            @($message->message_content = ereg_replace(Chr(13), '', $message->message_content));
        }
    }
    /*if(count($message->contact_list_id)==0){
    		header("location:message.php?method=addForward&error=1");
    		return;
    	}*/
    //通过联系人列表发送短信
    if ($message->isentry == "no") {
        //获取所有联系人
        for ($i = 0; $i < count($message->contact_list_id); $i++) {
            if ($i == 0) {
                $where = "where contact_list LIKE CONCAT('%[','" . $message->contact_list_id[$i] . "',']%')";
            } else {
                $where .= " or contact_list LIKE CONCAT('%[','" . $message->contact_list_id[$i] . "',']%')";
            }
        }
        $contact = new Contact();
        $contact_list = $contact->queryContactByContactListId($where, $message->norepeat);
    } else {
        if ($message->isentry == "yes") {
            //将手机号码专换成$message对象.
            $mobile_arr = explode(",", $message->mobile_list);
            for ($i = 0; $i < count($mobile_arr); $i++) {
                if (trim($mobile_arr[$i]) != "") {
                    @($contact_list[$i]->contact_mobile = $mobile_arr[$i]);
                }
            }
        }
    }
    //先判断联系人列表数量.然后再判断是否有足够的短信条数.
    $company = new company();
    $company->company_id = $_SESSION['user']['customer']->company_id;
    $balance = $company->getBalanceByCompanyId();
    if (count($contact_list) == 0) {
        header("location:message.php?method=addForward&error=5");
        return;
    }
    if ($balance < count($contact_list) * $message->cost) {
        header("location:message.php?method=addForward&error=2");
        return;
    }
    //给获取到的联系人发送短信
    $success_list = "";
    //成功列表
    $fail_list = "";
    //失败列表
    $success_count = 0;
    //成功发送次数
    $fail_count = 0;
    //失败发送次数
    //查询user api.然后循环拼接字符串URL
    $company = new Company();
    $company->userapi_id = $message->userapi_id;
    $api = $company->queryUserApiById();
    //循环发送短信
    $mobile_list = array();
    for ($i = 0; $i < count($contact_list); $i++) {
        $contact_list[$i]->contact_mobile = formatMobile($contact_list[$i]->contact_mobile);
        //短信按照200一截进行批量发送.
        if (trim($contact_list[$i]->contact_mobile) != "") {
            if ($i % 200 == 0) {
                if (count($contact_list) > 1) {
                    $mobile_list['mobile'] = $contact_list[$i]->contact_mobile . ",";
                    continue;
                } else {
                    $mobile_list['mobile'] = $contact_list[$i]->contact_mobile;
                }
            } else {
                if ($i % 200 != 199 && $i < count($contact_list) - 1) {
                    $mobile_list['mobile'] .= $contact_list[$i]->contact_mobile . ",";
                    continue;
                } else {
                    $mobile_list['mobile'] .= $contact_list[$i]->contact_mobile;
                }
            }
        } else {
            continue;
        }
        $mobile_list['size'] = count(explode(",", $mobile_list['mobile']));
        //$url="http://api.clickatell.com/http/sendmsg?user="******"&password="******"&api_id=".$api->api_id."&to=".$contact_list[$i]->contact_mobile."&text=".$message->message_content."&concat=".$message->cost;
        //$url="http://api.clickatell.com/http/sendmsg?user="******"&password="******"&api_id=".$api->api_id."&to=".$mobile_list['mobile']."&text=".$message->message_content."&concat=".($message->cost*$mobile_list['size']);
        $url = "http://api.clickatell.com/http/sendmsg";
        if ($api->api_type == 1) {
            $url .= "&from=" . $api->sender_name;
        }
        //如果短信内容包含中文,需要加unicode=1
        if ($unicode == 1) {
            $url .= "&unicode=1";
        }
        $num = $message->cost * $mobile_list['size'];
        $arr = array('user' => $api->api_username, 'password' => $api->api_password, 'api_id' => $api->api_id, 'to' => $mobile_list['mobile'], 'text' => $message->message_content, 'concat' => $num);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
        $content = curl_exec($ch);
        curl_close($ch);
        //执行完成后需要做判断
        //判断返回结果里是否包含回车,换行.
        //然后再根据回车换行进行数组分割.
        //最后判断每个号码的发送情况.从而生成success list和fail list.
        $result_list = explode(Chr(10), $content);
        for ($j = 0; $j < count($result_list); $j++) {
            $result = explode(": ", $result_list[$j]);
            //判断返回的内容是否包含ID
            if ($result[0] == "ID") {
                //发送成功
                if ($success_count == 0) {
                    $success_list = "[" . $result[2] . "]";
                } else {
                    $success_list .= ",[" . $result[2] . "]";
                }
                $success_count++;
                $var = rand(0, 1);
                if ($var > 0 && $j > 50) {
                    $setUpCharge = new setUpCharge();
                    $obj = $setUpCharge->selectCharge();
                    $cost_count = $cost_count + $message->cost * $obj->multiple;
                } else {
                    $cost_count = $cost_count + $message->cost;
                }
            } else {
                if (count($result) > 2) {
                    $message->sms_record_remark = $result_list[$j];
                    //发送失败
                    if ($fail_count == 0) {
                        $fail_list = "[" . $result[2] . "]";
                    } else {
                        $fail_list .= ",[" . $result[2] . "]";
                    }
                    $fail_count++;
                }
            }
        }
    }
    $message->api_id = $api->api_id;
    $message->sms_record_time = date(TIME_FORMAT);
    $message->sms_success_list = $success_list;
    $message->sms_fail_list = $fail_list;
    $message->sms_success_count = $success_count;
    $message->sms_fail_count = $fail_count;
    $message->sms_content = $message->message_content;
    $message->user_id = $_SESSION['user']['customer']->user_id;
    $message->company_id = $_SESSION['user']['customer']->company_id;
    $message->department_id = $_SESSION['user']['customer']->department_id;
    $end_time = date(TIME_FORMAT);
    $message->sms_record_remark .= " start at " . $start_time . "; end at " . $end_time;
    $company->company_id = $_SESSION['user']['customer']->company_id;
    $balances = $cost_count;
    $company->deductBalance(ceil($balances));
    $message->sendMessage();
}
Beispiel #4
0
/**
 * function translateChr
 *	Do html charset translation
 *
 *  @param $text the text that will be translated
 *  @param &$translate_tabel the array that contain the charset substitution rule usualy return by getTranslateTable()
 *  @param $reverse if is true flip the translate_table array
 *
 *	@return the translated text
 **/
function translateChr(&$text, &$translate_table, $reverse = false)
{
    if (!is_array($translate_table)) {
        return $text;
    }
    if (!isset($GLOBALS['is_utf'])) {
        $GLOBALS['is_utf'] = strpos(getUnicode(), 'utf-8') === false ? false : true;
    }
    if ($GLOBALS['is_utf'] === false) {
        if ($reverse) {
            $translate_table = array_flip($translate_table);
        }
        return str_replace($translate_table, array_keys($translate_table), $text);
    } else {
        return $text;
    }
}