Jump to content

new presales contact form -> inserts as sales ticket


weeps

Recommended Posts

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');
?>

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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. :P

Link to comment
Share on other sites

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. :P

 

Yeah but where do I get the template variable from...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated