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:
<?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(0, 0, 0, $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(0, 0, 0, $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(0, 0, 0, date("m"), date("d") + 2, date("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(), $id, 0, "/", "DOMAIN", false, true);
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

.
Regards,
Jesús