Ejemplo n.º 1
0
 public static function getInvestorConversations($investorID)
 {
     global $db;
     $conversations = $db->select('conversations', '*', ['investor' => $investorID]);
     $toReturn = [];
     foreach ($conversations as $conversation) {
         $contact = Contacts::getContact($conversation['contact']);
         if ($contact['crm'] == 1) {
             array_push($toReturn, $conversation);
         }
     }
     return $conversations;
 }
Ejemplo n.º 2
0
 public static function getAssetContacts($assetID)
 {
     global $db;
     $contacts = $db->select('assetContacts', ['[><]contacts' => ["contact" => "id"], '[><]assets' => ["asset" => "id"]], ['contacts.id'], ['assets.id' => $assetID]);
     $toReturn = [];
     foreach ($contacts as $contact) {
         array_push($toReturn, Contacts::getContact($contact['id']));
     }
     // Adding investors contacts
     $assetInvestors = Investors::getAssetInvestors($assetID);
     foreach ($assetInvestors as $investor) {
         $investorContacts = Contacts::getInvestorContacts($investor['id']);
         $toReturn = array_merge($toReturn, $investorContacts);
     }
     return array_unique($toReturn, SORT_REGULAR);
 }
Ejemplo n.º 3
0
 /**
  * Create a new client
  * 
  * Executes the creation of new client in the IspConfig control panel
  * Note in order to not fail this command, it must meet the following requirements:
  * 
  * - The customer must be registered in the db.
  * - The customer has bought a hosting plan
  * 
  * @param      array      $task     Must be a valid task 
  * @return     integer    RemoteClientId
  * @access     public
  */
 public function create_client(array $task)
 {
     $clientId = "";
     if (empty($task)) {
         throw new Exception('Task empty.', '3000');
     }
     // Execute a custom event
     $this->events()->trigger('panels_create_client_before', __CLASS__, array('task' => $task));
     $server = self::getServer($task['orderitem_id'], 'web');
     // Connection to the SOAP system
     $client = $this->connect($server['server_id']);
     if (!$client) {
         throw new Exception("There is no way to connect the client with the IspConfig Panel.", "3010");
     }
     try {
         // Get all the customer information
         $customer = Customers::getAllInfo($task['customer_id']);
         // Get the client id saved previously in the customer information page
         $customAttribute = CustomAttributes::getAttribute($task['customer_id'], 'client_id');
         // Get the custom ISPConfig attribute set in the customer control panel
         if (is_numeric($customAttribute['value'])) {
             /**
              * Client_id (IspConfig Attribute Set in ShineISP database in the setup of the panel)
              * @see Shineisp_Controller_Plugin_SetupcPanelsModules
              */
             $clientId = $customAttribute['value'];
             $record = $client->client_get($this->getSession(), $clientId);
             if ($record == false) {
                 $clientId = "";
             }
         }
         // Customer Profile
         $record['company_name'] = $customer['company'];
         $record['contact_name'] = $customer['firstname'] . " " . $customer['lastname'];
         $record['customer_no'] = $customer['customer_id'];
         $record['vat_id'] = $customer['vat'];
         $record['email'] = $customer['email'];
         $record['street'] = !empty($customer['Addresses'][0]['address']) ? $customer['Addresses'][0]['address'] : "";
         $record['zip'] = !empty($customer['Addresses'][0]['code']) ? $customer['Addresses'][0]['code'] : "";
         $record['city'] = !empty($customer['Addresses'][0]['city']) ? $customer['Addresses'][0]['city'] : "";
         $record['state'] = !empty($customer['Addresses'][0]['area']) ? $customer['Addresses'][0]['area'] : "";
         $record['country'] = !empty($customer['Addresses'][0]['Countries']['code']) ? $customer['Addresses'][0]['Countries']['code'] : "";
         $record['mobile'] = Contacts::getContact($customer['customer_id'], "Mobile");
         $record['fax'] = Contacts::getContact($customer['customer_id'], "Fax");
         $record['telephone'] = Contacts::getContact($customer['customer_id']);
         // System Configuration
         $languagecode = Languages::get_code($customer['language_id']);
         $record['language'] = $languagecode;
         $record['usertheme'] = "default";
         $record['template_master'] = 0;
         $record['template_additional'] = "";
         $record['created_at'] = date('');
         $record['web_php_options'] = "no,fast-cgi,cgi,mod,suphp,php-fpm";
         $record['ssh_chroot'] = 'jailkit';
         // Get the Json encoded parameters in the task
         $parameters = json_decode($task['parameters'], true);
         // Match all the ShineISP product system attribute and IspConfig attributes (see below about info)
         $retval = self::matchFieldsValues($parameters, $record);
         if (is_array($retval)) {
             $record = array_merge($record, $retval);
         } else {
             Shineisp_Commons_Utilities::logs("No hosting attribute parameters have been set in ShineISP. Check the hosting product attributes section.", "ispconfig.log");
         }
         // Execute the SOAP action
         if (!empty($clientId) && is_numeric($clientId)) {
             $client->client_update($this->getSession(), $clientId, 1, $record);
         } else {
             $arrUsernames = array();
             $arrUsernames = self::generateUsernames($customer);
             // Check if username is available
             foreach ($arrUsernames as $username) {
                 if (!$client->client_get_by_username($this->getSession(), $username)) {
                     break;
                 }
             }
             // Create a random password string
             $password = Shineisp_Commons_Utilities::GenerateRandomString();
             $record['username'] = $username;
             $record['password'] = $password;
             // Save the setup in the service setup field
             OrdersItems::set_setup($task['orderitem_id'], array('url' => 'http://' . $server['ip'] . ':8080', 'username' => $username, 'password' => $password), "webpanel");
             // Adding the client in ISPConfig
             $clientId = $client->client_add($this->getSession(), 0, $record);
             // Update the custom customer attribute client_id
             CustomAttributes::saveElementsValues(array(array('client_id' => $clientId)), $task['customer_id'], "customers");
             // Execute a custom event
             $this->events()->trigger('panels_create_client_after', __CLASS__, array('task' => $task, 'clientid' => $clientId, 'customerdata' => $record));
         }
         // Create the log message
         Shineisp_Commons_Utilities::logs("ID: " . $task['action_id'] . " - " . __METHOD__ . " - Parameters: " . json_encode($record), "ispconfig.log");
         // Logout from the IspConfig Remote System
         $client->logout($this->getSession());
         return $clientId;
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::logs(__METHOD__ . ": " . $e->getMessage());
         echo $e->getMessage();
     }
 }
Ejemplo n.º 4
0
<?php

$this->respond(['GET', 'POST'], '/create', function ($request, $response, $service, $app) {
    $contactData = json_decode($request->body(), true);
    $id = Contacts::createContact($contactData);
    if ($id > 0) {
        $response->json(Result::success('Contact Created.', ['id' => $id]));
    } else {
        $response->json(Result::error('Contact Creation Failed.', ['id' => $id]));
    }
});
$this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $contactData = Contacts::getContact($id);
    $conversations = Conversations::getContactConversations($id);
    $result = array("contactData" => $contactData, "contactConversations" => $conversations);
    if ($contactData) {
        $response->json(Result::success('', $result));
    } else {
        $response->json(Result::error('Contact not found'));
    }
});
$this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $contactData = json_decode($request->body());
    $result = Contacts::updateContact($id, $contactData);
    if ($result > 0) {
        $response->json(Result::success('Contact Updated.'));
    } elseif ($result === 0) {
        $response->json(Result::success('Contact not Updated.'));
    } else {