Skip to content

Commit

Permalink
Merge pull request #2 from joomdev/dev
Browse files Browse the repository at this point in the history
Merging new features on Dev to Master
  • Loading branch information
actuallyakash committed Feb 26, 2019
2 parents 577e50c + f2b0861 commit 421b7d2
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 53 deletions.
3 changes: 1 addition & 2 deletions assets/css/style.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions forms/fielditem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<option value="email">MOD_JDSCF_TYPE_EMAIL_LBL</option>
<option value="number">MOD_JDSCF_TYPE_NUMBER_LBL</option>
<option value="url">MOD_JDSCF_TYPE_URL_LBL</option>
<option value="file">MOD_JDSCF_TYPE_FILE_LBL</option>
</field>
<field
name="label"
Expand Down
124 changes: 115 additions & 9 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand All @@ -15,19 +15,19 @@ public static function renderForm($params, $module) {
$fields = $params->get('fields', []);
foreach ($fields as $field) {
$field->id = \JFilterOutput::stringURLSafe('jdscf-' . $module->id . '-' . $field->name);
self::renderField($field, $module);
self::renderField($field, $module, $params);
}
}

public static function renderField($field, $module) {
public static function renderField($field, $module, $params) {
$label = new JLayoutFile('label', JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
$field_layout = self::getFieldLayout($field->type);
$input = new JLayoutFile('fields.' . $field_layout, JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
$layout = new JLayoutFile('field', JPATH_SITE . '/modules/mod_jdsimplecontactform/layouts');
if ($field->type == 'checkbox') {
$field->show_label = 0;
}
echo $layout->render(['field' => $field, 'label' => $label->render(['field' => $field]), 'input' => $input->render(['field' => $field, 'label' => self::getLabelText($field), 'module' => $module]), 'module' => $module]);
echo $layout->render(['field' => $field, 'label' => $label->render(['field' => $field]), 'input' => $input->render(['field' => $field, 'label' => self::getLabelText($field), 'module' => $module, 'params' => $params]), 'module' => $module]);
}

public static function getOptions($options) {
Expand Down Expand Up @@ -89,26 +89,69 @@ public static function submitForm($ajax = false) {
$labels[$field->name] = ['label' => self::getLabelText($field), 'type' => $field->type];
}

$cc_emails = [];
$values = [];
foreach ($jdscf as $name => $value) {
$values[$name] = $value;
if(is_array($value)) {
if(isset($value['email'])) {
$values[$name] = $value['email'];
if(isset($value['cc']) && $value['cc'] == 1) {
$cc_emails[] = $value['email'];
}
}
} else {
$values[$name] = $value;
}
}


$contents = [];
$attachments = [];
$errors = [];
foreach ($labels as $name => $fld) {
$value = isset($values[$name]) ? $values[$name] : '';
if ($fld['type'] == 'checkbox') {

if ($fld['type'] == 'checkboxes') {

$value = $_POST['jdscf'][$name]['cbs'];

if (is_array($value)) {
$value = implode(', ', $value);
} else {
$value = $value;
}
}

if ($fld['type'] == 'checkbox') {
$value = $_POST['jdscf'][$name]['cb'];
if (is_array($value)) {
$value = implode(',', $value);
} else {
$value = $value;
}
$value = empty($value) ? 'unchecked' : 'checked';
}

if ($fld['type'] == 'file') {
if(isset($_FILES['jdscf']['name'][$name])) {
$value = $_FILES['jdscf']['name'][$name];
$uploaded = self::uploadFile($_FILES['jdscf']['name'][$name], $_FILES['jdscf']['tmp_name'][$name]);
//filetype error
if(!empty($value)) {
if(!$uploaded) {
$errors[] = JText::_('MOD_JDSCF_UNSUPPORTED_FILE_ERROR');
}
}
if(!empty($uploaded)) {
$attachments[] = $uploaded;
}
}
}
if ($fld['type'] == 'textarea') {
if ($value) {
$value = nl2br($value);
}
}

$contents[] = [
"value" => $value,
"label" => $fld['label'],
Expand Down Expand Up @@ -167,7 +210,12 @@ public static function submitForm($ajax = false) {
}
// CC
$cc = !empty($params->get('email_cc', '')) ? $params->get('email_cc') : '';
$cc = explode(',', $cc);
$cc = empty($cc) ? [] : explode(",", $cc);
if(!empty($cc_emails)){
$cc = array_merge($cc, $cc_emails);
$cc = array_unique($cc);
}

if (!empty($cc)) {
$mailer->addCc($cc);
}
Expand All @@ -180,7 +228,20 @@ public static function submitForm($ajax = false) {
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setBody($html);
$send = $mailer->Send();
foreach($attachments as $attachment){
$mailer->addAttachment($attachment);
}
if(!empty($errors)) {
$app = JFactory::getApplication();
//showing all the validation errors
foreach ($errors as $error) {
$app->enqueueMessage(\JText::_($error), 'error');
}
}
else {
$send = $mailer->Send();
}

if ($send !== true) {
throw new \Exception(JText::_('MOD_JDSCFEMAIL_SEND_ERROR'));
}
Expand Down Expand Up @@ -283,4 +344,49 @@ public static function getJS($moduleid) {
return $GLOBALS['mod_jdscf_js_' . $moduleid];
}

public static function isCCMail($field, $params){
$sendcopy_email = $params->get('sendcopy_email', 0);
$sendcopyemail_field = $params->get('sendcopyemail_field', '');
$sendcopyemail_fields = explode(",", $sendcopyemail_field);
if($sendcopy_email && !empty($sendcopyemail_fields) && in_array($field->name, $sendcopyemail_fields)){
return true;
}else{
return false;
}
}

public static function uploadFile($name, $src) {
jimport('joomla.filesystem.file');
jimport('joomla.application.component.helper');

$fullFileName = JFile::stripExt($name);
$filetype = JFile::getExt($name);
$filename = JFile::makeSafe($fullFileName."_".mt_rand(10000000,99999999).".".$filetype);

$params = JComponentHelper::getParams('com_media');
$allowable = array_map('trim', explode(',', $params->get('upload_extensions')));

if ($filetype == '' || $filetype == false || (!in_array($filetype, $allowable) ))
{
return false;
}
else
{
$tmppath = JPATH_SITE . '/tmp';
if(!file_exists($tmppath.'/jdscf')){
mkdir($tmppath.'/jdscf',0777);
}
$folder = md5(time().'-'.$filename.rand(0,99999));
if(!file_exists($tmppath.'/jdscf/'.$folder)){
mkdir($tmppath.'/jdscf/'.$folder,0777);
}
$dest = $tmppath.'/jdscf/'.$folder.'/'.$filename;

$return = null;
if (JFile::upload($src, $dest)){
$return = $dest;
}
return $return;
}
}
}
15 changes: 14 additions & 1 deletion language/en-GB/en-GB.mod_jdsimplecontactform.ini
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ MOD_JDSCF_EMAIL_BCC_DESC="BCC email address to recieve submissions. Use comma to
MOD_JDSCF_EMAIL_TEMPLATE_LBL="Email Template"
MOD_JDSCF_EMAIL_TEMPLATE_DESC="Select the email template, The <b>default</b> template lists all fields in the order they exist in <br><b>{field:label}: {field:value}</b></br> format."

MOD_JDSCF_SEND_COPY="Send Copy of Email"
MOD_JDSCF_SEND_COPY_LBL_TITLE="Send me a copy"
MOD_JDSCF_SEND_COPY_DESCRIPTION="Displays a checkbox for users to send a copy of email to themselves."

MOD_JDSCF_SEND_COPY_EMAIL_FIELD="Enter Email Field Name"
MOD_JDSCF_SEND_COPY_LABEL="Enter Send Copy Label"

MOD_JDSCF_EMAIL_NAME="Enter name of email"
MOD_JDSCF_EMAIL_NAME_DESCRIPTION="Name of email input field to send a copy to."

MOD_JDSCF_EMAIL_CUSTOM_TEMPLATE_LBL="Custom Email Template"
MOD_JDSCF_EMAIL_CUSTOM_TEMPLATE_DESC="Enter your custom email template. You can use <b>{field:label}</b> for the field name, and <b>{field:value}</b> for user input value. Change <b>field</b> to the actual name of your input field."

Expand All @@ -135,12 +145,15 @@ MOD_JDSCF_REDIRECT_DESC="Enter a URL to redirect users after submission. Leave b
MOD_JDSCF_SUBMITBTN_CLASS_LBL="Submit button class"
MOD_JDSCF_SUBMITBTN_CLASS_DESC=""

MOD_JDSCF_UNSUPPORTED_FILE_ERROR="Unsupported Filetype"
MOD_JDSCF_AJAX_ERROR_ON_SUBMIT="Something went wrong! Please try again.";

MOD_JDSCF_DEFAULT_SUBJECT="New Submission%s"

MOD_JDSCF_TEXTAREA_ROWS_LBL="Rows"
MOD_JDSCF_TEXTAREA_ROWS_DESC=""

MOD_JDSCF_THANKYOU_DEFAULT="Thank you."
MOD_JDSCF_THANKYOU_DEFAULT="<div class='alert alert-success'>Thanks for reaching out!</div>"
MOD_JDSCF_BAD_REQUEST="Bad Request"
MOD_JDSCFEMAIL_SEND_ERROR="An error occurred while sending email."
MOD_JDSCF_MODULE_NOT_FOUND="Module not found"
Expand Down
2 changes: 1 addition & 1 deletion layouts/emails/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand Down
2 changes: 1 addition & 1 deletion layouts/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand Down
23 changes: 21 additions & 2 deletions layouts/fields/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand All @@ -21,8 +21,27 @@
$attrs[] = 'required';
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
}

$document = JFactory::getDocument();
$style = 'label.calendar_icon {'
. 'display: inherit;'
. 'cursor: pointer;'
. 'margin: 0px;'
. 'border-radius: 0;'
. '}';
$document->addStyleDeclaration($style);
?>
<input type="text" name="jdscf[<?php echo $field->name; ?>]" class="form-control" <?php echo implode(' ', $attrs); ?> />

<div class="input-group mb-2">
<input type="text" name="jdscf[<?php echo $field->name; ?>]" class="form-control" <?php echo implode(' ', $attrs); ?> autocomplete="off" />
<label class="calendar_icon" for="<?php echo $field->id; ?>">
<div class="input-group-prepend">
<div class="input-group-text">
<img height="16" width="16" src="data:image/svg+xml;base64,PHN2ZyBhcmlhLWhpZGRlbj0idHJ1ZSIgZm9jdXNhYmxlPSJmYWxzZSIgZGF0YS1wcmVmaXg9ImZhciIgZGF0YS1pY29uPSJjYWxlbmRhci1hbHQiIGNsYXNzPSJzdmctaW5saW5lLS1mYSBmYS1jYWxlbmRhci1hbHQgZmEtdy0xNCIgcm9sZT0iaW1nIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48cGF0aCBmaWxsPSJjdXJyZW50Q29sb3IiIGQ9Ik0xNDggMjg4aC00MGMtNi42IDAtMTItNS40LTEyLTEydi00MGMwLTYuNiA1LjQtMTIgMTItMTJoNDBjNi42IDAgMTIgNS40IDEyIDEydjQwYzAgNi42LTUuNCAxMi0xMiAxMnptMTA4LTEydi00MGMwLTYuNi01LjQtMTItMTItMTJoLTQwYy02LjYgMC0xMiA1LjQtMTIgMTJ2NDBjMCA2LjYgNS40IDEyIDEyIDEyaDQwYzYuNiAwIDEyLTUuNCAxMi0xMnptOTYgMHYtNDBjMC02LjYtNS40LTEyLTEyLTEyaC00MGMtNi42IDAtMTIgNS40LTEyIDEydjQwYzAgNi42IDUuNCAxMiAxMiAxMmg0MGM2LjYgMCAxMi01LjQgMTItMTJ6bS05NiA5NnYtNDBjMC02LjYtNS40LTEyLTEyLTEyaC00MGMtNi42IDAtMTIgNS40LTEyIDEydjQwYzAgNi42IDUuNCAxMiAxMiAxMmg0MGM2LjYgMCAxMi01LjQgMTItMTJ6bS05NiAwdi00MGMwLTYuNi01LjQtMTItMTItMTJoLTQwYy02LjYgMC0xMiA1LjQtMTIgMTJ2NDBjMCA2LjYgNS40IDEyIDEyIDEyaDQwYzYuNiAwIDEyLTUuNCAxMi0xMnptMTkyIDB2LTQwYzAtNi42LTUuNC0xMi0xMi0xMmgtNDBjLTYuNiAwLTEyIDUuNC0xMiAxMnY0MGMwIDYuNiA1LjQgMTIgMTIgMTJoNDBjNi42IDAgMTItNS40IDEyLTEyem05Ni0yNjB2MzUyYzAgMjYuNS0yMS41IDQ4LTQ4IDQ4SDQ4Yy0yNi41IDAtNDgtMjEuNS00OC00OFYxMTJjMC0yNi41IDIxLjUtNDggNDgtNDhoNDhWMTJjMC02LjYgNS40LTEyIDEyLTEyaDQwYzYuNiAwIDEyIDUuNCAxMiAxMnY1MmgxMjhWMTJjMC02LjYgNS40LTEyIDEyLTEyaDQwYzYuNiAwIDEyIDUuNCAxMiAxMnY1Mmg0OGMyNi41IDAgNDggMjEuNSA0OCA0OHptLTQ4IDM0NlYxNjBINDh2Mjk4YzAgMy4zIDIuNyA2IDYgNmgzNDBjMy4zIDAgNi0yLjcgNi02eiI+PC9wYXRoPjwvc3ZnPg==" alt="Calendar">
</div>
</div>
</label>
</div>

<?php
$js = 'var jdscf_picker_' . $module->id . ' = new Pikaday({'
Expand Down
4 changes: 2 additions & 2 deletions layouts/fields/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand All @@ -16,7 +16,7 @@
}
?>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][]" value="1" id="<?php echo $field->name; ?>" <?php echo implode(' ', $attrs); ?> />
<input class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][cb]" value="1" id="<?php echo $field->name; ?>" <?php echo implode(' ', $attrs); ?> />
<label class="form-check-label" for="<?php echo $field->name; ?>">
<?php echo $label; ?>
</label>
Expand Down
4 changes: 2 additions & 2 deletions layouts/fields/checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand All @@ -20,7 +20,7 @@
foreach ($options as $key => $option) {
?>
<div class="form-check<?php echo $optionslayout == 'inline' ? ' form-check-inline' : ''; ?>">
<input data-parsley-errors-container="#<?php echo $field->name; ?>-errors" class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][]" value="<?php echo $option['value']; ?>" id="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>" <?php echo implode(' ', $attrs); ?> />
<input data-parsley-errors-container="#<?php echo $field->name; ?>-errors" class="form-check-input" type="checkbox" name="jdscf[<?php echo $field->name; ?>][cbs][]" value="<?php echo $option['value']; ?>" id="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>" <?php echo implode(' ', $attrs); ?> />
<label class="form-check-label" for="<?php echo $field->name; ?>-<?php echo $option['value']; ?>-<?php echo $key; ?>">
<?php echo $option['text']; ?>
</label>
Expand Down
40 changes: 37 additions & 3 deletions layouts/fields/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand All @@ -14,8 +14,42 @@
$attrs[] = 'data-parsley-required-message="' . JText::sprintf('MOD_JDSCF_REQUIRED_ERROR', strip_tags($label)) . '"';
}
$attrs[] = 'id="' . $field->name . '-file-input"';
//fetching allowed types
$params = JComponentHelper::getParams('com_media');
$allowable = array_map('trim', explode(',', $params->get('upload_extensions')));
$allowedMaxSize = $params->get('upload_maxsize');
$document = JFactory::getDocument();
$style = '.filesize-err {'
. 'display: none;'
. 'margin-top: 10px;'
. '}';
$document->addStyleDeclaration($style);
?>
<div class="custom-file">
<input type="file" name="jdscf[<?php echo $field->name; ?>]" class="custom-file-input" <?php echo implode(' ', $attrs); ?>>
<input id="<?php echo $field->name; ?>-<?php echo $module->id; ?>" accept="<?php foreach ($allowable as $type) { echo ".".$type.","; } ?>" type="file" name="jdscf[<?php echo $field->name; ?>]" class="custom-file-input" <?php echo implode(' ', $attrs); ?>>
<label class="custom-file-label" for="<?php echo $field->name; ?>-file-input"><?php echo JText::_('MOD_JDSCF_FILE_BTN_LBL'); ?></label>
</div>
</div>

<div class="filesize-err filesize-error-<?php echo $field->name; ?>-<?php echo $module->id; ?> alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
File size is too big!
</div>


<?php
// File size validation
$js = 'var uploadField_'.$field->name.' = document.getElementById("' . $field->name . '-' .$module->id .'");';
$js .= 'uploadField_' . $field->name .'.onchange = function() {';
$js .= 'var fileSizeBytes = this.files[0].size;';
// $js .= 'var i = parseInt(Math.floor(Math.log(fileSizeBytes) / Math.log(1024)));';
// $js .= 'var fileSizeMb = parseFloat(Math.round(fileSizeBytes / Math.pow(1024, i), 2));';
$js .= 'var filesizeMb = fileSizeBytes/1024/1024;';

$js .= 'if(filesizeMb > ' . $allowedMaxSize .'){';
$js .= 'uploadField_'.$field->name.'.value = "";';
$js .= 'jQuery(".filesize-error-' . $field->name . '-' . $module->id . '").show();';
$js .= '}';
$js .= '};';

ModJDSimpleContactFormHelper::addJS($js, $module->id);
?>
2 changes: 1 addition & 1 deletion layouts/fields/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand Down
2 changes: 1 addition & 1 deletion layouts/fields/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* @package JD Simple Contact Form
* @author JoomDev https://www.joomdev.com
* @copyright Copyright (C) 2009 - 2018 JoomDev.
* @copyright Copyright (C) 2009 - 2019 JoomDev.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or Later
*/
// no direct access
Expand Down
Loading

0 comments on commit 421b7d2

Please sign in to comment.