Skip to content

Commit

Permalink
module for sending mail from pmCake
Browse files Browse the repository at this point in the history
  • Loading branch information
Zpartakov committed May 4, 2016
1 parent 87d54b4 commit 7b9a88c
Show file tree
Hide file tree
Showing 18 changed files with 1,039 additions and 16 deletions.
81 changes: 70 additions & 11 deletions config/sql/pmcake.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- MySQL dump 10.13 Distrib 5.5.47, for debian-linux-gnu (x86_64)
-- MySQL dump 10.13 Distrib 5.5.49, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: cake_pm
-- ------------------------------------------------------
Expand Down Expand Up @@ -246,7 +246,7 @@ CREATE TABLE `hours` (
`days_holidays` float(2,1) NOT NULL,
`note` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=latin1 COMMENT='hours to do current year';
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=latin1 COMMENT='hours to do current year';
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -344,6 +344,65 @@ CREATE TABLE `lesmigrations20130828` (
) ENGINE=MyISAM AUTO_INCREMENT=28178 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mail_answers`
--

DROP TABLE IF EXISTS `mail_answers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mail_answers` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`mailator_id` int(12) NOT NULL,
`date` datetime NOT NULL,
`last_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`fulltext` text NOT NULL,
`rem` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mailators`
--

DROP TABLE IF EXISTS `mailators`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mailators` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`pm_organization_id` int(12) NOT NULL,
`pm_project_id` int(12) NOT NULL,
`pm_task_id` int(12) NOT NULL,
`statut_id` int(11) NOT NULL,
`date` datetime NOT NULL,
`mailfrom` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mailto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mailcc` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`mailbcc` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`subject` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`body` text COLLATE utf8_unicode_ci NOT NULL,
`attachment` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`rem` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='a module for sending mail from pmCake';
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `mailators_answers`
--

DROP TABLE IF EXISTS `mailators_answers`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mailators_answers` (
`id` int(12) NOT NULL AUTO_INCREMENT,
`mailator_id` int(12) NOT NULL,
`mail_answer_id` int(12) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `obsoletelogins`
--
Expand Down Expand Up @@ -398,7 +457,7 @@ CREATE TABLE `patchadmins` (
`priv` tinyint(4) NOT NULL DEFAULT '1',
`meladmin` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=128 DEFAULT CHARSET=utf8;
) ENGINE=MyISAM AUTO_INCREMENT=129 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -521,7 +580,7 @@ CREATE TABLE `pm_menus` (
`moddate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`line_after` int(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='application menus';
) ENGINE=MyISAM AUTO_INCREMENT=113 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='application menus';
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -597,7 +656,7 @@ CREATE TABLE `pm_projects` (
`hourly_fee` int(3) NOT NULL,
`budget` int(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=MyISAM AUTO_INCREMENT=164 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -633,7 +692,7 @@ CREATE TABLE `pm_tasks` (
`milestone` char(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`mod_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7585 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=MyISAM AUTO_INCREMENT=7650 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -974,7 +1033,7 @@ CREATE TABLE `pm_tasks_pm_members` (
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`rem` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1638 DEFAULT CHARSET=latin1;
) ENGINE=InnoDB AUTO_INCREMENT=1673 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1010,7 +1069,7 @@ CREATE TABLE `pm_tasks_revs` (
`version_id` int(11) NOT NULL AUTO_INCREMENT,
`version_created` datetime NOT NULL,
PRIMARY KEY (`version_id`)
) ENGINE=MyISAM AUTO_INCREMENT=13518 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=MyISAM AUTO_INCREMENT=13836 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1046,7 +1105,7 @@ CREATE TABLE `pm_tasks_time` (
`created` datetime DEFAULT NULL,
`modified` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=33514 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=MyISAM AUTO_INCREMENT=33802 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
Expand Down Expand Up @@ -1377,7 +1436,7 @@ CREATE TABLE `zefiles` (
`created` datetime DEFAULT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=379 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
) ENGINE=MyISAM AUTO_INCREMENT=383 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

Expand All @@ -1389,4 +1448,4 @@ CREATE TABLE `zefiles` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2016-04-18 14:53:00
-- Dump completed on 2016-05-04 14:35:38
61 changes: 61 additions & 0 deletions controllers/mail_answers_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
class MailAnswersController extends AppController {

var $name = 'MailAnswers';

function index() {
$this->MailAnswer->recursive = 0;
$this->set('mailAnswers', $this->paginate());
}

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid mail answer', true));
$this->redirect(array('action' => 'index'));
}
$this->set('mailAnswer', $this->MailAnswer->read(null, $id));
}

function add() {
if (!empty($this->data)) {
$this->MailAnswer->create();
if ($this->MailAnswer->save($this->data)) {
$this->Session->setFlash(__('The mail answer has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The mail answer could not be saved. Please, try again.', true));
}
}
}

function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid mail answer', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->MailAnswer->save($this->data)) {
$this->Session->setFlash(__('The mail answer has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The mail answer could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->MailAnswer->read(null, $id);
}
}

function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for mail answer', true));
$this->redirect(array('action'=>'index'));
}
if ($this->MailAnswer->delete($id)) {
$this->Session->setFlash(__('Mail answer deleted', true));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Mail answer was not deleted', true));
$this->redirect(array('action' => 'index'));
}
}
7 changes: 7 additions & 0 deletions controllers/mailators_answers_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
class MailatorsAnswersController extends AppController {

var $name = 'MailatorsAnswers';
var $scaffold;

}
107 changes: 107 additions & 0 deletions controllers/mailators_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
class MailatorsController extends AppController {

var $name = 'Mailators';

public $components = array('Email');

function index() {
$this->Mailator->recursive = 0;
$this->set('mailators', $this->paginate());
}

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid mailator', true));
$this->redirect(array('action' => 'index'));
}
$this->set('mailator', $this->Mailator->read(null, $id));
}

function add() {


if (!empty($this->data)) {

$this->Mailator->create();

$pm_project_id=$this->data['Mailator']['pm_project_id'];
$pm_task_id=$this->data['Mailator']['pm_task_id'];

//print_r($this->data); exit;
//echo $this->data[Mailator][mailfrom]; exit;

$this->Email->from = trim($this->data['Mailator']['mailfrom']);

$this->Email->to = $this->data['Mailator']['mailto'];
$this->Email->bcc = $this->data['Mailator']['mailbcc'];
$this->Email->cc = $this->data['Mailator']['mailcc'];
$this->Email->subject = $this->data['Mailator']['subject'];
$this->Email->replyTo = $this->data['Mailator']['mailfrom'];
//$this->Email->template = 'simple_message'; // notez l'absence de '.ctp'
// Envoi en 'html', 'text' ou 'both' (par défaut c'est 'text')
$this->Email->sendAs = 'html'; // parce que nous aimons envoyer de jolis emails

$this->Email->send(nl2br($this->data['Mailator']['body']));

/* if ($this->Email->send(nl2br($this->data['Mailator']['body']))) {
$this->Session->setFlash(__('Email From me'), 'default', array('class' => 'success'));
}
*/
if ($this->Mailator->save($this->data)) {
$this->Session->setFlash(__('The mailator has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The mailator could not be saved. Please, try again.', true));
}

//$db =& ConnectionManager::getDataSource('default');
//$db->showLog();
}else{

$pm_project_id=$_GET['pm_project_id'];
$pm_task_id=$_GET['pm_task_id'];
}
$pmOrganizations = $this->Mailator->PmOrganization->find('list');
$pmProjects = $this->Mailator->PmProject->find('list');
$pmTasks = $this->Mailator->PmTask->find('list');
$statuts = $this->Mailator->Statut->find('list');
$this->set(compact('pmOrganizations', 'pmProjects', 'pmTasks', 'statuts'));
}

function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid mailator', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Mailator->save($this->data)) {
$this->Session->setFlash(__('The mailator has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The mailator could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Mailator->read(null, $id);
}
$pmOrganizations = $this->Mailator->PmOrganization->find('list');
$pmProjects = $this->Mailator->PmProject->find('list');
$pmTasks = $this->Mailator->PmTask->find('list');
$statuts = $this->Mailator->Statut->find('list');
$this->set(compact('pmOrganizations', 'pmProjects', 'pmTasks', 'statuts'));
}

function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for mailator', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Mailator->delete($id)) {
$this->Session->setFlash(__('Mailator deleted', true));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Mailator was not deleted', true));
$this->redirect(array('action' => 'index'));
}
}
28 changes: 24 additions & 4 deletions libs/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ function projet_nom_return($pid) {
echo "SQL error: " .mysql_error(); exit;
}

return utf8_encode(mysql_result($sql,0,'name'));
return $txt=utf8_encode(mysql_result($sql,0,'name'));
}

/*function to return the budget of a given project*/
Expand Down Expand Up @@ -670,10 +670,30 @@ function task_nom_print($pid) {
echo "<a href=\"" .CHEMIN. "pm_tasks/view/" .$pid ."\">";
echo mysql_result($sql,0,'name');
echo "</a>";



}

/*function to return the name of a given task*/
function task_nom_return($pid) {
$sql="SELECT name FROM pm_tasks WHERE id=".$pid;
#do and check sql
$sql=mysql_query($sql);
if(!$sql) {
echo "SQL error: " .mysql_error(); exit;
}
return utf8_encode(mysql_result($sql,0,'name'));
}

/*function to return the description of a given task*/
function task_description_return($pid) {
$sql="SELECT description FROM pm_tasks WHERE id=".$pid;
#do and check sql
$sql=mysql_query($sql);
if(!$sql) {
echo "SQL error: " .mysql_error(); exit;
}
return utf8_encode(mysql_result($sql,0,'description'));
}

/*time spent on a task*/
function total_hours_task($task_id) {
$sql2="
Expand Down
Loading

0 comments on commit 7b9a88c

Please sign in to comment.