Author Topic: Creating Users and tasks using forms from the website  (Read 4968 times)

jcaragones

  • Newbie
  • *
  • Posts: 4
    • View Profile
Creating Users and tasks using forms from the website
« on: September 20, 2010, 06:38:30 am »
Hi,

I'm creating a php file that creates contacts and tasks from a form of the website. The idea is to use Feng Office like a CRM, a user (contact in Feng Office) fills and submits the form of the website, a contact is created in Feng Office in a specific project, a task is also created, linked to the same project and also to the contact.  Here is the code:

Code: [Select]
<?php //ini_set('display_errors', 1);
//error_reporting(E_ALL);
define("CONSOLE_MODE"true);

require 
"library/phpmailer/class.phpmailer.php";
require_once 
"InitWIS.php";

//DATA FROM FORM
$firstname stripslashes($_POST["firstname"]);
$lastname  stripslashes($_POST["lastname"]);
$job_title  stripslashes($_POST["job_title"]);
$o_birthday  $_POST["o_birthday"];
$h_phone_number  stripslashes($_POST["h_phone_number"]);
$h_country stripslashes($_POST["h_country"]);
$h_zipcode stripslashes($_POST["h_zipcode"]);
$h_web_page $_POST["h_web_page"];
$email stripslashes($_POST["email"]);
$pass $_POST["pass"];
$encpass md5($pass);
$notes 'Singularities: '.stripslashes($_POST["notes1"]).'. Is a gift? '.stripslashes($_POST["notes2"]).'. Terms and Conditions Accepted: '.stripslashes($_POST["notes3"]);
$budgetcode md5($email.rand());
$problems 0;

//IS IT A NEW CONTACT?
$contact = new Contact();
$rows Contacts::getByEmail($_POST["email2"], false);


if (
count($rows)>0//OLD CONTACT --> NEXT STEP
{
$id $rows->getId();
        
$encpassant $rows->getMiddlename();
if ($encpass == $encpassant//En principi ha de ser el mateix que el primer cop
{
list($day$month$year) = explode("/"$o_birthday);
$o_birthday date("Y-m-d h:i:s"mktime(000$month$day$year, -1));

$rows->setFirstName($firstname);
$rows->setLastName($lastname);
$rows->setJobTitle($job_title);
$rows->setOBirthday($o_birthday);
$rows->setHPhoneNumber($h_phone_number);
$rows->setWCountry($h_country);
$rows->setHZipcode($h_zipcode);
$rows->setHWebPage($h_web_page);
$rows->setUpdatedById('5');
$rows->setEmail($email);
$notesant $rows->getNotes();
$notes $notes//Falten les anteriors
$rows->setNotes($notes);
$rows->setDepartment($budgetcode);
$rows->save();
}else $problems 1;
}
else 
//NEW CONTACT --> CREATE CONTACT AND GO TO NEXT STEP


list($day$month$year) = explode("/"$o_birthday);
$o_birthday date("Y-m-d h:i:s"mktime(000$month$day$year, -1));

$contact->setFirstName($firstname);
$contact->setLastName($lastname);
$contact->setJobTitle($job_title);
$contact->setOBirthday($o_birthday);
$contact->setHPhoneNumber($h_phone_number);
$contact->setWCountry($h_country);
$contact->setHZipcode($h_zipcode);
$contact->setHWebPage($h_web_page);
$contact->setCreatedById('5');
$contact->setUpdatedById('5');
$contact->setEmail($email);
$contact->setNotes($notes);
$contact->setMiddlename($encpass); //Es podria millorar
$contact->setDepartment($budgetcode); //Es podria millorar
$contact->save();

$tag = new Tags();
$tag->addObjectTag('Budget'$contact);

//NEED TO VERIFY CONTACT CREATION
$rows Contacts::getByEmail($_POST["email2"], false);
$id $rows->getId();
                        
//Link to project
$wo = new WorkspaceObject();
$wo->setWorkspaceId("5"); //Project XXX;
$wo->setObject($rows);
$wo->save();
}
if (
$problems == 1){

if(isset($_GET['lang']))
{
header("Location: X");
}else header("Location: Y");
}else{

//CREO LES TASQUES
$task = new ProjectTask();
$today date("Y-m-d h:i:s");
$tomorrow date("Y-m-d h:i:s"mktime(000date("m"), date("d") + 2date("Y"))); //Passat demà
$task->setText("New Contact");
$task->setAssignedToUserId("2"); //JESUS 2
$task->setStartDate($today);////////////////////DateTimeValue
$task->setDueDate($tomorrow);///////////////////////DateTimeValue
$task->setCreatedOn($today);///////////////////////DateTimeValue
$task->setCreatedById("5"); //WIS 5
$task->setAssignedOn($today);///////////////////////DateTimeValue
$task->setAssignedById("5"); //WIS 5
$task->setPriority(ProjectTasks::PRIORITY_HIGH); ///////////////////
$task->setTitle("New potential Customer");
//$task->setIsPrivate(false); // Not used, but defined as not null
$task->save();

$rows->linkObject($task);


 
$to $rows->getEmail();
 
$subject "XXX";
 
$name $rows->getFirstName();
 
$body "AAA";

  
  
$mail = new phpmailer();
  
$mail->PluginDir "library/phpmailer/";
  
$mail->Mailer "smtp";
  
$mail->Host "HOST";
  
$mail->SMTPAuth true;
  
$mail->Username "USER"
  
$mail->Password "PASSWORD";
  
$mail->From "FROM";
  
$mail->FromName "NAME";
  
$mail->Timeout=30//podria ser 10 (per defecte)
  
$mail->AddAddress($to);
  
$mail->Subject $subject;
  
$mail->Body $body;     //Sí HTML
  
$mail->AltBody $body;  //No HTML
  
$exito $mail->Send();
  
$intentos=1
  while ((!
$exito) && ($intentos 5)) {
sleep(5);
     
$exito $mail->Send();
     
$intentos=$intentos+1;

   }
if(
$exito){

session_start();
setcookie(session_id(), $id0"/""DOMAIN"falsetrue);
if(isset($_GET['lang']))
{
  
    header("Location: X");
} else header("Location: Y");
} else {
echo "There has been a problem: ".$valor."We apologise for the inconvenients this may cause.";
echo "<br/>".$mail->ErrorInfo;
}
}
?>

First of all I wnat to say that.... yes the code is crap I'm sure that there is a better way to do that.

My problems are:
 
1.(LOCALHOST)  I can create the contact, link it to the project, create the task and link it to the contact. But I can't link the task to the project. (I haven posted the code to link the task with the project but I tried several ways).
2.(ONLINE SERVER) I can create the contact and link to the project. I'm not able to create the task.This problem could be related to the PHP version but I'm not able to see what happens even using the error_reporting.

So It works almost perfect when executing this on my localhost but for some reason I can't create tasks "ONLINE" (it is the same code).

The last issue (long term issue) is: Is Feng Office team thinking in creating an interface to be able to do all this using a "website-feng office intercface user"?

Can anyone help me with all this? Thank you!
By the way: congratulation, the software is amazing  :D.

Regards,
Jesús

franponce87

  • Administrator
  • Hero Member
  • *****
  • Posts: 1819
    • View Profile
    • Email
Re: Creating Users and tasks using forms from the website
« Reply #1 on: October 01, 2010, 01:20:03 pm »
Hello there! Welcome to Feng Office boards!
Your idea actually is a great one! Have you been able to fix those problems you had? Otherwise we may give you some help!
Best regards,
Francisco
Would you like to install Feng Office Professional or Enterprise Edition in your servers? No problem! Read this article!

jcaragones

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating Users and tasks using forms from the website
« Reply #2 on: October 01, 2010, 03:25:19 pm »
Hi Francisco!

To be honest I did not have time to get into this. I've been solving other issues of my website. It would be perfect if you could help me with this one. Thank you!!

Jesús Cid Aragonès

jcaragones

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Creating Users and tasks using forms from the website
« Reply #3 on: October 25, 2010, 03:39:40 pm »
Hi there,

Finally I solved this I paste the code below:
Code: [Select]
<?php 
//..........CODE........
                //Task creation
                
$task = new ProjectTask();
$today date("Y-m-d h:i:s");
$tomorrow date("Y-m-d h:i:s"mktime(000date("m"), date("d") + 2date("Y")));
$task->setText($notes);
$task->setAssignedToUserId("2");
$task->setStartDate($today);
$task->setDueDate($tomorrow);
$task->setCreatedOn($today);
$task->setCreatedById("5"); 
$task->setAssignedOn($today);
$task->setAssignedById("5"); 
$task->setPriority(ProjectTasks::PRIORITY_HIGH);
$task->setTitle("New quotation for ".$name);
$task->setIsPrivate(false); // Not used, but defined as not null
$task->save();

                
//Link with Contact
                
$rows2 Contacts::findById($id);
$rows2->linkObject($task);

                
//Link with Project
$wo2 = new WorkspaceObject();
$wo2->setWorkspaceId("5");
$wo2->setObject($task);
$wo2->save();
//........CODE......
?>

With this code you can create a task link it to a contact and to a project. I don't know if this is the best way but it works...

Jesús