diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index c11cc4a74d6..f3a123ba386 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -367,6 +367,15 @@ function project_admin_prepare_head() $head[$h][2] = 'attributes_task'; $h++; + if (! empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) { + $langs->load("members"); + + $head[$h][0] = DOL_URL_ROOT.'/projet/admin/website.php'; + $head[$h][1] = $langs->trans("BlankSubscriptionForm"); + $head[$h][2] = 'website'; + $h++; + } + complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove'); return $head; diff --git a/htdocs/projet/admin/website.php b/htdocs/projet/admin/website.php new file mode 100644 index 00000000000..e84cceb68a8 --- /dev/null +++ b/htdocs/projet/admin/website.php @@ -0,0 +1,160 @@ + + * Copyright (C) 2006-2015 Laurent Destailleur + * Copyright (C) 2006-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/projet/admin/website.php + * \ingroup member + * \brief File of main public page for project module to catch lead + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + +// Load translation files required by the page +$langs->loadLangs(array("admin", "members")); + +$action = GETPOST('action', 'aZ09'); + +if (!$user->admin) accessforbidden(); + + +/* + * Actions + */ + +if ($action == 'setPROJECT_ENABLE_PUBLIC') { + if (GETPOST('value')) dolibarr_set_const($db, 'PROJECT_ENABLE_PUBLIC', 1, 'chaine', 0, '', $conf->entity); + else dolibarr_set_const($db, 'PROJECT_ENABLE_PUBLIC', 0, 'chaine', 0, '', $conf->entity); +} + +if ($action == 'update') { + $public = GETPOST('PROJECT_ENABLE_PUBLIC'); + + $res = dolibarr_set_const($db, "PROJECT_ENABLE_PUBLIC", $public, 'chaine', 0, '', $conf->entity); + + if (!($res > 0)) $error++; + + if (!$error) { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } else { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} + + +/* + * View + */ + +$form = new Form($db); + +$help_url = ''; +llxHeader('', $langs->trans("ProjectsSetup"), $help_url); + + +$linkback = ''.$langs->trans("BackToModuleList").''; +print load_fiche_titre($langs->trans("ProjectsSetup"), $linkback, 'title_setup'); + +$head = project_admin_prepare_head(); + +$param = ''; + +print '
'; +print ''; +print ''; + +print dol_get_fiche_head($head, 'website', $langs->trans("Projects"), -1, 'user'); + + +print ''.$langs->trans("LeadPublicFormDesc").'

'; + + +$enabledisablehtml = $langs->trans("EnablePublicLeadForm").' '; +if (empty($conf->global->PROJECT_ENABLE_PUBLIC)) { + // Button off, click to enable + $enabledisablehtml .= ''; + $enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off'); + $enabledisablehtml .= ''; +} else { + // Button on, click to disable + $enabledisablehtml .= ''; + $enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on'); + $enabledisablehtml .= ''; +} +print $enabledisablehtml; +print ''; + +/* +print '
'; + +if (!empty($conf->global->PROJECT_ENABLE_PUBLIC)) { + print '
'; + + print ''; + + print ''; + print ''; + print ''; + print "\n"; + + // param + print '\n"; + + print '
'.$langs->trans("Parameter").''.$langs->trans("Value").'
'; + print $langs->trans("CanEditAmount"); + print ''; + print $form->selectyesno("MEMBER_NEWFORM_EDITAMOUNT", (!empty($conf->global->MEMBER_NEWFORM_EDITAMOUNT) ? $conf->global->MEMBER_NEWFORM_EDITAMOUNT : 0), 1); + print "
'; + + print '
'; + print ''; + print '
'; +} +*/ + +print dol_get_fiche_end(); + +print '
'; + + +if (!empty($conf->global->PROJECT_ENABLE_PUBLIC)) { + print '
'; + //print $langs->trans('FollowingLinksArePublic').'
'; + print img_picto('', 'globe').' '.$langs->trans('BlankSubscriptionForm').':
'; + if ($conf->multicompany->enabled) { + $entity_qr = '?entity='.$conf->entity; + } else { + $entity_qr = ''; + } + + // Define $urlwithroot + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + print ''.$urlwithroot.'/public/project/new.php'.$entity_qr.''; +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/public/project/new.php b/htdocs/public/project/new.php new file mode 100644 index 00000000000..3c1c4169286 --- /dev/null +++ b/htdocs/public/project/new.php @@ -0,0 +1,436 @@ + + * Copyright (C) 2001-2002 Jean-Louis Bergamo + * Copyright (C) 2006-2013 Laurent Destailleur + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2012 J. Fernando Lagrange + * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2018 Alexandre Spangaro + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/public/lead/new.php + * \ingroup project + * \brief Example of form to add a new lead + */ + +if (!defined('NOLOGIN')) define("NOLOGIN", 1); // This means this output page does not require to be logged. +if (!defined('NOCSRFCHECK')) define("NOCSRFCHECK", 1); // We accept to go on this page from external web site. +if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +if (!defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); +if (!defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip + +// For MultiCompany module. +// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php +// TODO This should be useless. Because entity must be retrieve from object ref and not from url. +$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1)); +if (is_numeric($entity)) define("DOLENTITY", $entity); + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; + +// Init vars +$errmsg = ''; +$num = 0; +$error = 0; +$backtopage = GETPOST('backtopage', 'alpha'); +$action = GETPOST('action', 'aZ09'); + +// Load translation files +$langs->loadLangs(array("main", "members", "companies", "install", "other")); + +// Security check +if (empty($conf->projet->enabled)) accessforbidden('', 0, 0, 1); + +if (empty($conf->global->PROJECT_ENABLE_PUBLIC)) { + print $langs->trans("Form for public lead registration has not been enabled"); + exit; +} + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('publicnewleadcard', 'globalcard')); + +$extrafields = new ExtraFields($db); + +$object = new Project($db); + +$user->loadDefaultValues(); + + +/** + * Show header for new member + * + * @param string $title Title + * @param string $head Head array + * @param int $disablejs More content into html header + * @param int $disablehead More content into html header + * @param array $arrayofjs Array of complementary js files + * @param array $arrayofcss Array of complementary css files + * @return void + */ +function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '') +{ + global $user, $conf, $langs, $mysoc; + + top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); // Show html headers + + print ''; + + // Define urllogo + $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png'; + + if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_small); + } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) { + $urllogo = DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/'.$mysoc->logo); + } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) { + $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg'; + } + + print '
'; + // Output html code for logo + if ($urllogo) { + print '
'; + print '
'; + print ''; + print '
'; + if (empty($conf->global->MAIN_HIDE_POWERED_BY)) { + print ''; + } + print '
'; + } + print '
'; + + print '
'; +} + +/** + * Show footer for new member + * + * @return void + */ +function llxFooterVierge() +{ + print '
'; + + printCommonFooter('public'); + + print "\n"; + print "\n"; +} + + + +/* + * Actions + */ +$parameters = array(); +// Note that $action and $object may have been modified by some hooks +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +// Action called when page is submitted +if (empty($reshook) && $action == 'add') { + $error = 0; + $urlback = ''; + + $db->begin(); + + // test if lead already exists + /* + if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) { + if (!GETPOST('login')) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Login"))."
\n"; + } + $sql = "SELECT login FROM ".MAIN_DB_PREFIX."adherent WHERE login='".$db->escape(GETPOST('login'))."'"; + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + } + if ($num != 0) { + $error++; + $langs->load("errors"); + $errmsg .= $langs->trans("ErrorLoginAlreadyExists")."
\n"; + } + if (!GETPOSTISSET("pass1") || !GETPOSTISSET("pass2") || GETPOST("pass1", 'none') == '' || GETPOST("pass2", 'none') == '' || GETPOST("pass1", 'none') != GETPOST("pass2", 'none')) { + $error++; + $langs->load("errors"); + $errmsg .= $langs->trans("ErrorPasswordsMustMatch")."
\n"; + } + if (!GETPOST("email")) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("EMail"))."
\n"; + } + } + */ + if (GETPOST('type') <= 0) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."
\n"; + } + if (!in_array(GETPOST('morphy'), array('mor', 'phy'))) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv('Nature'))."
\n"; + } + if (empty($_POST["lastname"])) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Lastname"))."
\n"; + } + if (empty($_POST["firstname"])) { + $error++; + $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Firstname"))."
\n"; + } + if (GETPOST("email") && !isValidEmail(GETPOST("email"))) { + $error++; + $langs->load("errors"); + $errmsg .= $langs->trans("ErrorBadEMail", GETPOST("email"))."
\n"; + } + + if (!$error) { + // email a peu pres correct et le login n'existe pas + $proj = new Project($db); + $proj->statut = -1; + $proj->email = GETPOST("email"); + $proj->note_private = GETPOST("note_private"); + + + // Fill array 'array_options' with data from add form + $extrafields->fetch_name_optionals_label($proj->table_element); + $ret = $extrafields->setOptionalsFromPost(null, $proj); + if ($ret < 0) $error++; + + $result = $proj->create($user); + if ($result > 0) { + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $object = $proj; + + if ($object->email) { + $subject = ''; + $msg = ''; + + // Send subscription email + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + // Set output language + $outputlangs = new Translate('', $conf); + $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang); + // Load traductions files required by page + $outputlangs->loadLangs(array("main", "members")); + // Get email content from template + $arraydefaultmessage = null; + $labeltouse = $conf->global->PROJECT_EMAIL_TEMPLATE_AUTOLEAD; + + if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'project', $user, $outputlangs, 0, 1, $labeltouse); + + if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { + $subject = $arraydefaultmessage->topic; + $msg = $arraydefaultmessage->content; + } + + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); + $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnValid()), $substitutionarray, $outputlangs); + + if ($subjecttosend && $texttosend) { + $moreinheader = 'X-Dolibarr-Info: send_an_email by public/lead/new.php'."\r\n"; + + $result = $object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); + } + /*if ($result < 0) { + $error++; + setEventMessages($object->error, $object->errors, 'errors'); + }*/ + } + + if (!empty($backtopage)) { + $urlback = $backtopage; + } elseif (!empty($conf->global->PROJECT_URL_REDIRECT_LEAD)) { + $urlback = $conf->global->PROJECT_URL_REDIRECT_LEAD; + // TODO Make replacement of __AMOUNT__, etc... + } else { + $urlback = $_SERVER["PHP_SELF"]."?action=added"; + } + + if (!empty($entity)) $urlback .= '&entity='.$entity; + dol_syslog("project lead ".$proj->ref." was created, we redirect to ".$urlback); + } else { + $error++; + $errmsg .= join('
', $proj->errors); + } + } + + if (!$error) { + $db->commit(); + + Header("Location: ".$urlback); + exit; + } else { + $db->rollback(); + } +} + +// Action called after a submitted was send and member created successfully +// If MEMBER_URL_REDIRECT_SUBSCRIPTION is set to url we never go here because a redirect was done to this url. +// backtopage parameter with an url was set on member submit page, we never go here because a redirect was done to this url. +if (empty($reshook) && $action == 'added') { + llxHeaderVierge($langs->trans("NewMemberForm")); + + // Si on a pas ete redirige + print '
'; + print '
'; + print $langs->trans("NewMemberbyWeb"); + print '
'; + + llxFooterVierge(); + exit; +} + + + +/* + * View + */ + +$form = new Form($db); +$formcompany = new FormCompany($db); +$extrafields->fetch_name_optionals_label('project'); // fetch optionals attributes and labels + + +llxHeaderVierge($langs->trans("NewContact")); + + +print load_fiche_titre($langs->trans("NewContact"), '', '', 0, 0, 'center'); + + +print '
'; +print '
'; + +print '
'; +if (!empty($conf->global->PROJECT_NEWFORM_TEXT)) { + print $langs->trans($conf->global->PROJECT_NEWFORM_TEXT)."
\n"; +} else { + print $langs->trans("NewLeadDesc", $conf->global->MAIN_INFO_SOCIETE_MAIL)."
\n"; +} +print '
'; + +dol_htmloutput_errors($errmsg); + +// Print form +print '
'."\n"; +print ''; +print ''; +print ''; + +print '
'; + +print '
'.$langs->trans("FieldsWithAreMandatory", '*').'
'; +//print $langs->trans("FieldsWithIsForPublic",'**').'
'; + +print dol_get_fiche_head(''); + +print ''; + + +print ''."\n"; + +// Lastname +print ''."\n"; +// Firstname +print ''."\n"; +// Company +print ''."\n"; +// Address +print ''."\n"; +// Zip / Town +print ''; +// Country +print ''; +// State +if (empty($conf->global->SOCIETE_DISABLE_STATE)) { + print ''; +} +// EMail +print ''."\n"; +// Other attributes +$tpl_context = 'public'; // define template context to public +include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php'; +// Comments +print ''; +print ''; +print ''; +print ''."\n"; + +print "
'.$langs->trans("Lastname").' *
'.$langs->trans("Firstname").' *
'.$langs->trans("Company").'
'.$langs->trans("Address").''."\n"; +print '
'.$langs->trans('Zip').' / '.$langs->trans('Town').''; +print $formcompany->select_ziptown(GETPOST('zipcode'), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6, 1); +print ' / '; +print $formcompany->select_ziptown(GETPOST('town'), 'town', array('zipcode', 'selectcountry_id', 'state_id'), 0, 1); +print '
'.$langs->trans('Country').''; +$country_id = GETPOST('country_id'); +if (!$country_id && !empty($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE)) { + $country_id = getCountry($conf->global->PROJECT_NEWFORM_FORCECOUNTRYCODE, 2, $db, $langs); +} +if (!$country_id && !empty($conf->geoipmaxmind->enabled)) { + $country_code = dol_user_country(); + //print $country_code; + if ($country_code) { + $new_country_id = getCountry($country_code, 3, $db, $langs); + //print 'xxx'.$country_code.' - '.$new_country_id; + if ($new_country_id) $country_id = $new_country_id; + } +} +$country_code = getCountry($country_id, 2, $db, $langs); +print $form->select_country($country_id, 'country_id'); +print '
'.$langs->trans('State').''; + if ($country_code) print $formcompany->select_state(GETPOST("state_id"), $country_code); + else print ''; + print '
'.$langs->trans("Email").' *
'.$langs->trans("Comments").'
\n"; + +print dol_get_fiche_end(); + +// Save +print '
'; +print ''; +if (!empty($backtopage)) { + print '     '; +} +print '
'; + + +print "
\n"; +print "
"; +print '
'; + + +llxFooterVierge(); + +$db->close();