private function process()
 {
     $this->commonProcess();
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $mail = services::getService('mail');
     $geo = services::getService('geoinfo');
     $categories = services::getService('cats');
     if ($params->getParam('add_to_adressbook')) {
         $addr = new adressbook();
         $addr->sender_id = $this->user->id;
         $addr->recipient_id = $params->getParam('showmember');
         if (!$addr->find()) {
             $addr->insert();
             $this->addMsg('msg_adressbook_add_success');
         } else {
             $this->addMsg('msg_adressbook_add_allready');
         }
     }
     // build userlist
     // assotiativ array with object and detail-flag
     $smember = new user();
     $smember->id = $params->getParam('showmember');
     $smember->find(true);
     $member = array("obj" => $smember);
     $this->member = $member;
     $this->member['obj']->getPhoto();
     $this->geodist = $geo->getDistance($this->user, $this->member["obj"]);
 }
Пример #2
0
<?php

if (!$_POST) {
    echo "ERROR, Post is empty";
} else {
    $adressbook = new adressbook();
    if ($_POST['f'] == 'updateContacts') {
        $returnedData = $adressbook->getAllContacts();
        print_r($returnedData);
    } elseif ($_POST['f'] == 'delAll') {
        $adressbook->delAll();
    } elseif ($_POST['f'] == 'addNewContact') {
        $msg = $adressbook->addNewContact($_POST);
        print_r($msg);
    } else {
        echo "function doesn't exist";
    }
}
class adressbook
{
    private $dbConnection;
    function __construct()
    {
        $this->dbConnection = new PDO("mysql:host=localhost;dbname=test", "root", "");
        $this->dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    }
    private function sqlExecQuery($query, $amountRetriving)
    {
        if ($amountRetriving == 'm') {
            try {
                // prepare sql and bind parameters
 private function process()
 {
     $mail = services::getService('mail');
     $config = services::getService('config');
     $lang = services::getService('lang');
     $params = services::getService('pageParams');
     $categories = services::getService('cats');
     // function is set
     if ($params->getParam('function')) {
         $this->function = $params->getParam('function');
     } else {
         $this->function = 'inbox';
     }
     // view
     if ($this->function == 'view') {
         $view = new pm();
         $view->id = $params->getParam('msg_id');
         $view->find(true);
         if ($view->recipient_id == $this->user->id || $view->sender_id == $this->user->id) {
             if ($view->recipient_id == $this->user->id) {
                 $view->fetchSender();
                 $delete = clone $view;
                 $delete->delete();
                 $view->is_read = 1;
                 $view->insert();
             }
             if ($view->sender_id == $this->user->id) {
                 $view->fetchRecipient();
             }
             $this->view = clone $view;
         }
     }
     // inbox
     if ($this->function == 'inbox') {
         // delete
         if ($params->getParam('delete')) {
             $msg = new pm();
             $msg->id = $params->getParam('delete');
             $msg->find();
             $msg->fetch();
             if ($msg->recipient_id == $this->user->id) {
                 $delete = clone $msg;
                 $delete->delete();
                 $msg->recipient_delete = 1;
                 $msg->insert();
                 $this->addMsg('msg_msg_deleted');
             }
         }
         // mark read
         if ($params->getParam('markread')) {
             $msg = new pm();
             $msg->id = $params->getParam('markread');
             $msg->find();
             $msg->fetch();
             if ($msg->recipient_id == $this->user->id) {
                 $delete = clone $msg;
                 $delete->delete();
                 $msg->is_read = 1;
                 $msg->insert();
             }
         }
         // get list
         $msgs = new pm();
         $msgs->recipient_id = $this->user->id;
         $msgs->recipient_delete = 0;
         $msgs->orderBy('is_read ASC, date DESC');
         $msgs->find();
         while ($msgs->fetch()) {
             $msgs->fetchSender();
             $this->inbox[] = clone $msgs;
         }
     }
     // sent
     if ($this->function == 'sent') {
         $msgs = new pm();
         $msgs->sender_id = $this->user->id;
         $msgs->orderBy('date DESC');
         $msgs->find();
         while ($msgs->fetch()) {
             $msgs->fetchRecipient();
             $this->sent[] = clone $msgs;
         }
     }
     if ($this->function == 'new') {
         if ($params->getParam('recipient')) {
             $this->msgform = new formPM('msgform', $params->getParam('recipient'));
             $recipient = new user();
             $recipient->id = $params->getParam('recipient');
             $recipient->find(true);
             $this->recipient = clone $recipient;
             if ($params->getParam('answer')) {
                 $answer = new pm();
                 $answer->id = $params->getParam('answer');
                 $answer->find(true);
                 $this->msgform->setDefaults(array('title' => 'Re: ' . $answer->title));
             }
             if ($this->msgform->validate()) {
                 $msg = new pm();
                 $msg->recipient_id = $this->msgform->exportValue('recipient');
                 $msg->sender_id = $this->user->id;
                 $msg->title = $this->msgform->exportValue('title');
                 $msg->body = $this->msgform->exportValue('body');
                 $msg->is_in_draft = 0;
                 $msg->is_read = 0;
                 $msg->recipient_delete = 0;
                 $msg->sender_delete = 0;
                 $msg->date = time();
                 $msg->insert();
                 $addr = new adressbook();
                 $addr->recipient_id = $this->msgform->exportValue('recipient');
                 $addr->sender_id = $this->user->id;
                 if (!$addr->find()) {
                     $addr->insert();
                 }
                 // send email
                 $recipient = new user();
                 $recipient->id = $this->msgform->exportValue('recipient');
                 $recipient->find(true);
                 $mail->send('new_pm', $recipient, $this->user);
                 $this->switchPage('pm&function=inbox&msg=msg_msg_sent');
             }
         } else {
             if ($params->getParam('delete')) {
                 $delete = new adressbook();
                 $delete->sender_id = $this->user->id;
                 $delete->recipient_id = $params->getParam('delete');
                 $delete->delete();
                 $this->addMsg('msg_contact_deleted');
             }
             $addr = new adressbook();
             $addr->sender_id = $this->user->id;
             $addr->find();
             while ($addr->fetch()) {
                 $addr->fetchRecipient();
                 $this->adressbook[] = clone $addr;
             }
         }
     }
     $this->commonProcess();
 }