function sendMail($smTo, $smSubject, $smBody)
{
    global $mainframe;
    $subject = $smSubject;
    $message_body = nl2br($smBody);
    $to = $smTo;
    $from = fetchParam('admin_email');
    $fromName = fetchParam('admin_name');
    $mailer =& JFactory::getMailer();
    // Build e-mail message format
    $mailer->setSender(array('' . $from . '', '' . $fromName . ''));
    $mailer->setSubject(stripslashes($subject));
    $mailer->setBody($message_body);
    $mailer->IsHTML(1);
    $mailer->addRecipient($to);
    // Send the Mail
    $rs = $mailer->Send();
    // Check for an error
    if (JError::isError($rs)) {
        return false;
    } else {
        return true;
    }
}
Example #2
0
function submit()
{
    //unset($_SESSION['RSM_error']);
    //unset($_SESSION['RSM_post']);
    $session = JFactory::getSession();
    $session->set('RSM_error', '');
    $session->set('RSM_post', '');
    $session->set('RSM_rc', '');
    $isfalse = false;
    $RSM_error = array();
    if (fetchParam('login_to_submit_testimonial') == 'true') {
        $user =& JFactory::getUser();
        $usr_id = $user->get('id');
        if ($usr_id > 0) {
        } else {
            $isfalse = true;
            $RSM_error[] = JText::_('RSM_MSG_ERR_LOGIN_FAIL');
        }
    }
    if (fetchParam('show_single_name_field') != 'false') {
        if (trim($_POST['fname']) == '') {
            $isfalse = true;
            $RSM_error[] = JText::_('RSM_MSG_ERR_NAME');
        }
    } else {
        if (trim($_POST['fname']) == '') {
            $isfalse = true;
            $RSM_error[] = JText::_('RSM_MSG_ERR_FNAME');
        }
        if (trim($_POST['lname']) == '') {
            $isfalse = true;
            $RSM_error[] = JText::_('RSM_MSG_ERR_LNAME');
        }
    }
    if (!eregi("^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})\$", trim($_POST['email']))) {
        $isfalse = true;
        $RSM_error[] = JText::_('RSM_MSG_ERR_EMAIL');
    }
    if (fetchParam('show_image') == 'true') {
        if (is_uploaded_file($_FILES['testi_pic']['tmp_name'])) {
            $max_s = fetchParam('image_max_size');
            $max_h = fetchParam('image_max_height');
            $max_w = fetchParam('image_max_width');
            $err = '';
            $img_settings = getimagesize($_FILES['testi_pic']['tmp_name']);
            if ($img_settings[2] != 1 && $img_settings[2] != 2 && $img_settings[2] != 3) {
                $isfalse = true;
                $RSM_error[] = JText::_('RSM_MSG_ERR_PICTURE_NOT_SUPPORTED');
            } else {
                if ($_FILES['testi_pic']['size'] > $max_s * 1024) {
                    $isfalse = true;
                    $RSM_error[] = JText::sprintf('RSM_MSG_ERR_PICTURE_IS_OVER_SIZE', $max_w, $max_h, $max_s);
                } else {
                    if ($img_settings[0] > $max_w) {
                        $isfalse = true;
                        $RSM_error[] = JText::sprintf('RSM_MSG_ERR_PICTURE_IS_OVER_SIZE', $max_w, $max_h, $max_s);
                    } else {
                        if ($img_settings[1] > $max_h) {
                            $isfalse = true;
                            $RSM_error[] = JText::sprintf('RSM_MSG_ERR_PICTURE_IS_OVER_SIZE', $max_w, $max_h, $max_s);
                        } else {
                        }
                    }
                }
            }
        }
    }
    if (fetchParam('show_captcha') != 'false') {
        if (fetchParam('use_recaptcha') == 'true') {
            require_once JPATH_BASE . DS . 'components' . DS . 'com_rsmonials' . DS . 'includes' . DS . 'recaptchalib.php';
            $rs_rc_privatekey = fetchParam('recaptcha_private_key');
            $rs_rc_resp = recaptcha_check_answer($rs_rc_privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
            if ($rs_rc_resp->is_valid) {
            } else {
                $rs_rc_error = $rs_rc_resp->error;
                $isfalse = true;
                $RSM_error[] = JText::_('RSM_MSG_ERR_SECURITY_CODE');
            }
        } else {
            if ($session->get("RSM_code") != $_POST['security_code']) {
                $isfalse = true;
                $RSM_error[] = JText::_('RSM_MSG_ERR_SECURITY_CODE');
            }
        }
    }
    if (trim($_POST['comments']) == '') {
        $isfalse = true;
        $RSM_error[] = JText::_('RSM_MSG_ERR_COMMENTS');
    }
    if ($isfalse == false) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = safeHTML($value);
        }
        $database =& JFactory::getDBO();
        if (fetchParam('auto_approval') == 'true') {
            $tesistatus = 1;
        } else {
            $tesistatus = 2;
        }
        $database->setQuery("insert into `#__" . RSWEBSOLS_TABLE_PREFIX . "`(`id`, `fname`, `lname`, `about`, `location`, `website`, `email`, `comment`, `date`, `status`) values('', '" . $database->getEscaped($_POST['fname']) . "', '" . $database->getEscaped($_POST['lname']) . "', '" . $database->getEscaped($_POST['about']) . "', '" . $database->getEscaped($_POST['location']) . "', '" . $database->getEscaped($_POST['website']) . "', '" . $database->getEscaped($_POST['email']) . "', '" . $database->getEscaped($_POST['comments']) . "', '" . date('Y-m-d') . "', '" . $tesistatus . "')");
        $database->query();
        if (is_uploaded_file($_FILES['testi_pic']['tmp_name'])) {
            $new_t_id = $database->insertid();
            $upload_dir_path = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials';
            if (!file_exists($upload_dir_path)) {
                mkdir($upload_dir_path, 0755);
            }
            $upload_path = $upload_dir_path . DS . $new_t_id . '.';
            $img_settings = getimagesize($_FILES['testi_pic']['tmp_name']);
            if ($img_settings[2] == 1) {
                $upload_path .= 'gif';
            } else {
                if ($img_settings[2] == 2) {
                    $upload_path .= 'jpg';
                } else {
                    if ($img_settings[2] == 3) {
                        $upload_path .= 'png';
                    }
                }
            }
            move_uploaded_file($_FILES['testi_pic']['tmp_name'], $upload_path);
        }
        if (fetchParam('admin_email_alert') == 'true') {
            $smFrom = $_POST['email'];
            $smName = $_POST['fname'] . ' ' . $_POST['lname'];
            $smSubject = JText::_('RSM_EMAIL_ADMIN_SUBJECT');
            $smBody = JText::_('RSM_EMAIL_ADMIN_BODY');
            sendMail($smFrom, $smName, $smSubject, $smBody);
        }
        header('location:' . JRoute::_("index.php?option=com_rsmonials&Itemid=" . $_REQUEST['Itemid'] . "&saved=true", false) . '');
        exit;
    } else {
        //$_SESSION['RSM_error'] = $RSM_error;
        //$_SESSION['RSM_post'] = $_POST;
        $session->set('RSM_error', $RSM_error);
        $session->set('RSM_post', $_POST);
        $session->set('RSM_rc', $rs_rc_error);
        header('location:' . JRoute::_("index.php?option=com_rsmonials&Itemid=" . $_REQUEST['Itemid'] . "&err=true#submitform", false) . '');
        exit;
    }
}
function save()
{
    /*foreach($_POST as $key=>$value) {
    		$_POST[$key] = addslashes($value);
    	}*/
    $database =& JFactory::getDBO();
    $postingArr = explode("-", $_POST['posting_date']);
    $mktime = mktime(12, 0, 0, $postingArr[1], $postingArr[2], $postingArr[0]);
    if (date('Y', $mktime) > 1979) {
        $date = date('Y-m-d', $mktime);
    } else {
        $date = date('Y-m-d');
    }
    if ($_POST['id'] > 0) {
        $database->setQuery("update `#__" . RSWEBSOLS_TABLE_PREFIX . "` set `fname`='" . $database->getEscaped($_POST['fname']) . "', `lname`='" . $database->getEscaped($_POST['lname']) . "', `about`='" . $database->getEscaped($_POST['about']) . "', `location`='" . $database->getEscaped($_POST['location']) . "', `website`='" . $database->getEscaped($_POST['website']) . "', `email`='" . $database->getEscaped($_POST['email']) . "', `comment`='" . $database->getEscaped($_POST['comments']) . "', `date`='" . $date . "' where `id`='" . $_POST['id'] . "'");
    } else {
        $database->setQuery("insert into `#__" . RSWEBSOLS_TABLE_PREFIX . "`(`id`, `fname`, `lname`, `about`, `location`, `website`, `email`, `comment`, `date`, `status`) values('', '" . $database->getEscaped($_POST['fname']) . "', '" . $database->getEscaped($_POST['lname']) . "', '" . $database->getEscaped($_POST['about']) . "', '" . $database->getEscaped($_POST['location']) . "', '" . $database->getEscaped($_POST['website']) . "', '" . $database->getEscaped($_POST['email']) . "', '" . $database->getEscaped($_POST['comments']) . "', '" . $date . "', '1')");
    }
    $database->query();
    if ($_POST['id'] > 0) {
        $new_id = $_POST['id'];
    } else {
        $new_id = $database->insertid();
    }
    $img_ext = array('jpg', 'jpeg', 'gif', 'png');
    // Image Delete
    if ($_POST['testi_pic_del'] == 'true') {
        $testi_pic_file = '';
        if (file_exists(JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.gif')) {
            $testi_pic_file = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.gif';
        } else {
            if (file_exists(JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.png')) {
                $testi_pic_file = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.png';
            } else {
                if (file_exists(JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.jpg')) {
                    $testi_pic_file = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.jpg';
                } else {
                    if (file_exists(JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.jpeg')) {
                        $testi_pic_file = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials' . DS . $_POST['id'] . '.jpeg';
                    }
                }
            }
        }
        if ($testi_pic_file != '') {
            unlink($testi_pic_file);
        }
    }
    // Image Upload
    if (is_uploaded_file($_FILES['testi_pic']['tmp_name'])) {
        $max_s = fetchParam('image_max_size');
        $max_h = fetchParam('image_max_height');
        $max_w = fetchParam('image_max_width');
        $err = '';
        $img_settings = getimagesize($_FILES['testi_pic']['tmp_name']);
        if ($img_settings[2] != 1 && $img_settings[2] != 2 && $img_settings[2] != 3) {
            $err = 'IMAGE UPLOADING ERROR: File is not supported. Please upload jpg, gif or png file.';
        } else {
            if ($_FILES['testi_pic']['size'] > $max_s * 1024) {
                $err = ' IMAGE UPLOADING ERROR: Image is larger than ' . $max_s . ' kb';
            } else {
                if ($img_settings[0] > $max_w) {
                    $err = ' IMAGE UPLOADING ERROR: Image width is larger than ' . $max_w . ' px';
                } else {
                    if ($img_settings[1] > $max_h) {
                        $err = ' IMAGE UPLOADING ERROR: Image height is larger than ' . $max_h . ' px';
                    } else {
                        $upload_dir_path = JPATH_ROOT . DS . 'images' . DS . 'com_rsmonials';
                        if (!file_exists($upload_dir_path)) {
                            mkdir($upload_dir_path, 0755);
                        }
                        $upload_path = $upload_dir_path . DS . $new_id . '.';
                        if ($img_settings[2] == 1) {
                            $upload_path .= 'gif';
                        } else {
                            if ($img_settings[2] == 2) {
                                $upload_path .= 'jpg';
                            } else {
                                if ($img_settings[2] == 3) {
                                    $upload_path .= 'png';
                                }
                            }
                        }
                        if (!move_uploaded_file($_FILES['testi_pic']['tmp_name'], $upload_path)) {
                            $err = ' IMAGE UPLOADING ERROR: Failed to Upload Image.';
                        }
                    }
                }
            }
        }
    }
    header("location:index.php?option=" . $_REQUEST['option'] . "&task=" . $_REQUEST['task'] . "&page=" . $_REQUEST['page'] . "&limit=" . $_REQUEST['limit'] . "&result=" . base64_encode('Testimonial Successfully Saved.' . $err) . "");
    exit;
}