weeps Posted October 17, 2007 Share Posted October 17, 2007 The old presales contact form didn't really do what I needed so I created my own that inserts the entries into sales tickets instead of emailing it to you. This uses the same templates, language files and everything else as the actual presales form so you can simply swap the old file for this new one (keep a backup). If anyone notices any bugs please let me know. <?php // contact.php // $path = "/home/username/www/clients/"; $capatacha = true; $language = "English"; //notify someone that a ticket has been opened (will email the sales department email that you enter in whmcs) $notify = true; $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $db = ""; // check the table tblticketdepartments to get the department id for sales $department_id = "003"; //DO NOT EDIT BELOW THIS LINE session_start(); require $path.'libs/Smarty.class.php'; $lang = file_get_contents($path."lang/".$language.".txt"); eval($lang); $smarty = new Smarty; $sent = false; if($_GET["action"] == "send") { $error = false; $errormessage = ""; if(md5($_POST["code"]) != $_SESSION["image_random_value"]) { $error = true; $errormessage .= "[*] ".$_LANG["imagecheck"]; } if(strlen($_POST["name"]) == 0) { $error = true; $errormessage .= "[*] ".$_LANG["contacterrorname"]; } if(strlen($_POST["subject"]) == 0) { $error = true; $errormessage .= "[*] ".$_LANG["contacterrorsubject"]; } if(strlen($_POST["message"]) == 0) { $error = true; $errormessage .= "[*] ".$_LANG["contacterrormessage"]; } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST["email"])) { $error = true; $errormessage .= "[*] ".$_LANG["clientareaerroremailinvalid"]; } if(!$error) { $sent = true; $link = mysql_connect($dbhost, $dbuser, $dbpass) or die('Could not connect: ' . mysql_error()); mysql_select_db($db) or die('Could not select database'); srand(time()); $tid = (rand()% 999999); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % strlen($chars); $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } $query = "insert into tbltickets (tid, did, userid, name, email, c, date, title, "; $query .= "message, status, urgency, admin, lastreply, flag, clientunread, adminunread) "; $query .= "values ('".$tid."','".$department_id."','0000000000', '".mysql_escape_string($_POST['name'])."', '".mysql_escape_string($_POST['email'])."', '".$pass."', NOW(), "; $query .= "'".mysql_escape_string($_POST['subject'])."', '".mysql_escape_string($_POST['message'])."', 'Open', 'Medium', '', NOW(), 0, 0, 1)"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); if($notify) { $query = "select email from tblticketdepartments where id = '".$department_id."'"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); $row = mysql_fetch_array($result, MYSQL_NUM); $email = $row[0]; mail($email, "New sales ticket has been opened", "New sales ticket has been opened"); } } else { $sent = false; } } if($error) { $smarty->assign("errormessage", $errormessage); } $smarty->assign("name", $_POST["name"]); $smarty->assign("email", $_POST["email"]); $smarty->assign("subject", $_POST["subject"]); $smarty->assign("message", $_POST["message"]); $smarty->assign("sent", $sent); $smarty->assign("pagetitle", $_LANG["contacttitle"]); $smarty->assign("LANG", $_LANG); $smarty->assign("capatacha", $capatacha); $smarty->display($path.'templates/default/header.tpl'); $smarty->display($path.'templates/default/contact.tpl'); $smarty->display($path.'templates/default/footer.tpl'); ?> 0 Quote Link to comment Share on other sites More sharing options...
impactgc Posted October 17, 2007 Share Posted October 17, 2007 Sure I will ask a stupid question -- Will this send an email out to the sales group as well. I don't see it here -- but thought I would would ask. Great job btw. Adam 0 Quote Link to comment Share on other sites More sharing options...
apollo1 Posted October 17, 2007 Share Posted October 17, 2007 Nice work. At the bottom though, shouldn't these lines be picking up the template from some variable? smarty->display($path.'templates/default/header.tpl'); $smarty->display($path.'templates/default/contact.tpl'); $smarty->display($path.'templates/default/footer.tpl'); 0 Quote Link to comment Share on other sites More sharing options...
weeps Posted October 17, 2007 Author Share Posted October 17, 2007 Sure I will ask a stupid question -- Will this send an email out to the sales group as well. I don't see it here -- but thought I would would ask. Great job btw. Adam It now emails the sales department that a ticket has been opened. 0 Quote Link to comment Share on other sites More sharing options...
weeps Posted October 17, 2007 Author Share Posted October 17, 2007 Nice work. At the bottom though, shouldn't these lines be picking up the template from some variable? smarty->display($path.'templates/default/header.tpl'); $smarty->display($path.'templates/default/contact.tpl'); $smarty->display($path.'templates/default/footer.tpl'); Not too sure what you mean.. 0 Quote Link to comment Share on other sites More sharing options...
impactgc Posted October 17, 2007 Share Posted October 17, 2007 Thanks 0 Quote Link to comment Share on other sites More sharing options...
apollo1 Posted October 18, 2007 Share Posted October 18, 2007 Nice work. At the bottom though, shouldn't these lines be picking up the template from some variable? smarty->display($path.'templates/default/header.tpl'); $smarty->display($path.'templates/default/contact.tpl'); $smarty->display($path.'templates/default/footer.tpl'); Not too sure what you mean.. The reference to "default" ... your code is forcing the use of the default template. What if someone is using a different template? Isn't there a variable representing the template the user configured, in which case you could substitute "defualt" with the name of the variable instead. 0 Quote Link to comment Share on other sites More sharing options...
impactgc Posted October 18, 2007 Share Posted October 18, 2007 Also is there a way to use the configuration file instead of having the connection string in this file? 0 Quote Link to comment Share on other sites More sharing options...
weeps Posted October 18, 2007 Author Share Posted October 18, 2007 Also is there a way to use the configuration file instead of having the connection string in this file? Theres no way for me to know what the variable names are in the config file since the whmcs files are all encrypted. 0 Quote Link to comment Share on other sites More sharing options...
arteryplanet Posted October 18, 2007 Share Posted October 18, 2007 Wondering how this work if you have disabled the support tickets for no registered clients? They will be able to click in the link in the email to see the opened ticket at helpdeks, also what happen if they reply to the email? will go through to the helpdesk? (considering that if they are not a registered client the helpdesk will discard any email sent to the piping email addresses) Thanx! 0 Quote Link to comment Share on other sites More sharing options...
railto Posted October 18, 2007 Share Posted October 18, 2007 i was looking at this, but the fact that i have to hard code the connection string and the support department variables is really putting me off using it 0 Quote Link to comment Share on other sites More sharing options...
impactgc Posted October 18, 2007 Share Posted October 18, 2007 I betcha matt can adjust this code in less the a minute matt -- Adam 0 Quote Link to comment Share on other sites More sharing options...
Jordan Posted October 18, 2007 Share Posted October 18, 2007 Also is there a way to use the configuration file instead of having the connection string in this file? Theres no way for me to know what the variable names are in the config file since the whmcs files are all encrypted. $smarty->display($path.'templates/{template}/header.tpl'); $smarty->display($path.'templates/{template}/contact.tpl'); $smarty->display($path.'templates/{template}/footer.tpl'); There ya go. 0 Quote Link to comment Share on other sites More sharing options...
weeps Posted October 18, 2007 Author Share Posted October 18, 2007 Also is there a way to use the configuration file instead of having the connection string in this file? Theres no way for me to know what the variable names are in the config file since the whmcs files are all encrypted. $smarty->display($path.'templates/{template}/header.tpl'); $smarty->display($path.'templates/{template}/contact.tpl'); $smarty->display($path.'templates/{template}/footer.tpl'); There ya go. Yeah but where do I get the template variable from... 0 Quote Link to comment Share on other sites More sharing options...
Jordan Posted October 18, 2007 Share Posted October 18, 2007 Your form should bring up the proper directory, as that was a Smarty variable I added in there. {template} will bring up the directory being used, if a user has to use an absolute url. I use this when I have to link images, that are under the template's folder. So when I have images in Smarty templates, they are linked like: [img=/templates/{template}/images/graphic.gif] If I didn't specify the URL as so, putting /images/graphic.gif would have picked up from the /images/ directory in the root of the WHMCS install. I can only assume that this would handle the same way, with your form. This {template} would pick up the template the user is using. So your CODING looks like templates/{template}, but when it's EXECUTED it will display as templates/userstemplatebeingused/. Get it? 0 Quote Link to comment Share on other sites More sharing options...
Roger Posted October 18, 2007 Share Posted October 18, 2007 This code: $smarty->display($path.'templates/{template}/header.tpl'); $smarty->display($path.'templates/{template}/contact.tpl'); $smarty->display($path.'templates/{template}/footer.tpl'); is failing - Warning: Smarty error: unable to read resource: '/home/xxxxx/public_html/templates/{template}/header.tpl' in /home/xxxxx/public_html/libs/Smarty.class.php on line 1095 Warning: Smarty error: unable to read resource: "/home/xxxxx/public_html/templates/{template}/contact.tpl" in /home/xxxxx/public_html/libs/Smarty.class.php on line 1095 Warning: Smarty error: unable to read resource: "/home/xxxxx/public_html/templates/{template}/footer.tpl" in /home/xxxxx/public_html/libs/Smarty.class.php on line 1095 any thoughts .. what have I done wrong?? 0 Quote Link to comment Share on other sites More sharing options...
Jordan Posted October 18, 2007 Share Posted October 18, 2007 I'm guessing that you can't use a Smarty function in your code. You're going to have to notate that a user will have to enter in the folder name of their template at the bottom (and anywhere else it's required.) 0 Quote Link to comment Share on other sites More sharing options...
Roger Posted October 18, 2007 Share Posted October 18, 2007 Please understand I'm just trying to learn something here... That's the same code from earlier in the thread. I did try hard coding my template folder in it and the page is displayed, but with no style info. edited: Forgot to add this is a part of the overall code from this thread Thanks... 0 Quote Link to comment Share on other sites More sharing options...
weeps Posted October 18, 2007 Author Share Posted October 18, 2007 You can't use the smarty variables in the code, only in the templates. Just edit my code in the original post to point to your template. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted October 18, 2007 WHMCS CEO Share Posted October 18, 2007 If you wanted users to open tickets with pre-sales enquiries rather than having a contact form which emails you seperately, then wouldn't just changing the link from contact.php to http://demo.whmcs.com/submitticket.php?step=2&deptid=002 be easier in the homepage.tpl template file? Matt 0 Quote Link to comment Share on other sites More sharing options...
Jordan Posted October 18, 2007 Share Posted October 18, 2007 If you wanted users to open tickets with pre-sales enquiries rather than having a contact form which emails you seperately, then wouldn't just changing the link from contact.php to http://demo.whmcs.com/submitticket.php?step=2&deptid=002 be easier in the homepage.tpl template file? Matt Alternatively, you can just swap the form details from submitticket.tpl (or whatever it is) for contact.tpl and then have it set so that there's only ONE choice hardcoded (eg: contact). And in the support section, just make sure to create a contact department / email. That would essentially work, correct? EDIT: It worked like a charm. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.