<commit_before><?php

/*
 * Copyright (C) 2006-2011 <NAME>, <NAME>, Cyber IT Solutions
 * Pty. Ltd.
 * 
 * This file is part of the allocPSA application <<EMAIL>>.
 * 
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * allocPSA is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/


/**
*
* This class provides methods for web services to access key parts of
* alloc's functionality.
*
* The inline PHPDoc-style comments, provide information for WSDL_Gen so that
* the alloc.wsdl file can be dynamically generated by running `make soap`.
*
* You must run `make soap` every time modifications are made to this class.
* You MUST ensure that the PHPDoc parameter definitions are correct. 
*
*/

class alloc_services {

  public function __construct($sessID="") {
    global $current_user; 
    $current_user = $this->get_current_user($sessID);
  }

  /** The authenticate function
   * @param string $username
   * @param string $password
   * @return string $sessID
   */
  public function authenticate($username,$password) {
    $person = new person;
    $sess = new Session;
    $row = $person->get_valid_login_row($username,$password); 
    if ($row) {
      $sess->Start($row,false);
      $sess->UseGet();
      $sess->Save();
      return $sess->GetKey();
    } else {
      die("Authentication Failed(1)."); 
    }
  }  

  private function get_current_user($sessID) {
    $sess = new Session($sessID);
    if (!$sess->Started()) {
      die("Authentication Failed(2).");
    } else {
      $person = new person;
      $person->load_current_user($sess->Get("personID"));
      return $person;
    }
  }

  /** The get_task_comments function
   * @param int $taskID
   * @return array $comments
   */
  public function get_task_comments($taskID) {
    //global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    if ($taskID) {
      $task = new task;
      $task->set_id($taskID);
      $task->select();
      return $task->get_task_comments_array();
    }
  }

  public function get_people($people="") {
    $person_table = get_cached_table("person");

    $people = explode(",",$people);
    foreach ($people as $person) {
      // personID
      if (is_numeric($person)) {
        $rtn[$person] = $person_table[$person];

      // username
      } else if (strpos($person," ") === false) {
        foreach ($person_table as $pid => $data) {
          strtolower($person) == strtolower($data["username"]) and $rtn[$pid] = $data;
        }
  
      // full name
      } else {
        foreach ($person_table as $pid => $data) {
          strtolower($person) == strtolower($data["name"]) and $rtn[$pid] = $data;
        }
      }
    }
    foreach ($rtn as $pid => $p) {
      $rtn[$pid] = $this->reduce_person_info($p);
    }
    return (array)$rtn;
  }

  function reduce_person_info($person) {
    $rtn["personID"] = $person["personID"];
    $rtn["username"] = $person["username"];
    $rtn["name"]     = $person["name"];
    $rtn["emailAddress"] = $person["emailAddress"];
    return $rtn;
  }


  /** The add_timeSheetItem_by_task function
   * @param int $taskID
   * @param string $duration
   * @param string $date
   * @param string $comments
   * @return array $timeSheetID
   */
  public function add_timeSheetItem($options) {
    //global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    $rtn = timeSheet::add_timeSheetItem($options);
    if ($rtn["status"] == "yay") {
      return $rtn["message"];
    } else {
      die(print_r($rtn,1));
    }
  }

   /** The change_timeSheet_status function
   * @param int $timeSheetID
   * @param string $direction
   * @return int $timeSheetID
   */
  public function change_timeSheet_status($timeSheetID,$direction) {
    $timeSheet = new timeSheet();
    $timeSheet->set_id($timeSheetID);
    $timeSheet->select();
    return $timeSheet->change_status($direction);
  }

  public function get_tfID($name) {
    return tf::get_tfID($name);
  } 

  /** The get_list function
   * @param string $entity
   * @param mixed $options
   * @return array $list
   */
  public function get_list($entity, $options=array()) {

    if ($entity == "tf" || $entity == "transaction")
      die("Functionality disabled, pending security review.");

    global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    if (class_exists($entity)) {
      $options = obj2array($options);
      $e = new $entity;
      if (method_exists($e, "get_list")) {
        ob_start();
        $rtn = $e->get_list($options);
        $echoed = ob_get_contents();
        if (!$rtn && $echoed) {
          return array("error"=>$echoed);
        } else {
          if (isset($rtn["rows"])) {
            return $rtn["rows"];
          } else {
            return $rtn;
          }
        }
      } else {
        die("Entity method '".$entity."->get_list()' does not exist."); <commit_msg>19246 CLI Enabled `alloc accounts`.<commit_after><?php

/*
 * Copyright (C) 2006-2011 <NAME>, <NAME>, Cyber IT Solutions
 * Pty. Ltd.
 * 
 * This file is part of the allocPSA application <<EMAIL>>.
 * 
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * 
 * allocPSA is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.
*/


/**
*
* This class provides methods for web services to access key parts of
* alloc's functionality.
*
* The inline PHPDoc-style comments, provide information for WSDL_Gen so that
* the alloc.wsdl file can be dynamically generated by running `make soap`.
*
* You must run `make soap` every time modifications are made to this class.
* You MUST ensure that the PHPDoc parameter definitions are correct. 
*
*/

class alloc_services {

  public function __construct($sessID="") {
    global $current_user; 
    $current_user = $this->get_current_user($sessID);
  }

  /** The authenticate function
   * @param string $username
   * @param string $password
   * @return string $sessID
   */
  public function authenticate($username,$password) {
    $person = new person;
    $sess = new Session;
    $row = $person->get_valid_login_row($username,$password); 
    if ($row) {
      $sess->Start($row,false);
      $sess->UseGet();
      $sess->Save();
      return $sess->GetKey();
    } else {
      die("Authentication Failed(1)."); 
    }
  }  

  private function get_current_user($sessID) {
    $sess = new Session($sessID);
    if (!$sess->Started()) {
      die("Authentication Failed(2).");
    } else {
      $person = new person;
      $person->load_current_user($sess->Get("personID"));
      return $person;
    }
  }

  /** The get_task_comments function
   * @param int $taskID
   * @return array $comments
   */
  public function get_task_comments($taskID) {
    //global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    if ($taskID) {
      $task = new task;
      $task->set_id($taskID);
      $task->select();
      return $task->get_task_comments_array();
    }
  }

  public function get_people($people="") {
    $person_table = get_cached_table("person");

    $people = explode(",",$people);
    foreach ($people as $person) {
      // personID
      if (is_numeric($person)) {
        $rtn[$person] = $person_table[$person];

      // username
      } else if (strpos($person," ") === false) {
        foreach ($person_table as $pid => $data) {
          strtolower($person) == strtolower($data["username"]) and $rtn[$pid] = $data;
        }
  
      // full name
      } else {
        foreach ($person_table as $pid => $data) {
          strtolower($person) == strtolower($data["name"]) and $rtn[$pid] = $data;
        }
      }
    }
    foreach ($rtn as $pid => $p) {
      $rtn[$pid] = $this->reduce_person_info($p);
    }
    return (array)$rtn;
  }

  function reduce_person_info($person) {
    $rtn["personID"] = $person["personID"];
    $rtn["username"] = $person["username"];
    $rtn["name"]     = $person["name"];
    $rtn["emailAddress"] = $person["emailAddress"];
    return $rtn;
  }


  /** The add_timeSheetItem_by_task function
   * @param int $taskID
   * @param string $duration
   * @param string $date
   * @param string $comments
   * @return array $timeSheetID
   */
  public function add_timeSheetItem($options) {
    //global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    $rtn = timeSheet::add_timeSheetItem($options);
    if ($rtn["status"] == "yay") {
      return $rtn["message"];
    } else {
      die(print_r($rtn,1));
    }
  }

   /** The change_timeSheet_status function
   * @param int $timeSheetID
   * @param string $direction
   * @return int $timeSheetID
   */
  public function change_timeSheet_status($timeSheetID,$direction) {
    $timeSheet = new timeSheet();
    $timeSheet->set_id($timeSheetID);
    $timeSheet->select();
    return $timeSheet->change_status($direction);
  }

  public function get_tfID($name) {
    return tf::get_tfID($name);
  } 

  /** The get_list function
   * @param string $entity
   * @param mixed $options
   * @return array $list
   */
  public function get_list($entity, $options=array()) {
    global $current_user; // Always need this :(
    //$current_user = $this->get_current_user($sessID);
    if (class_exists($entity)) {
      $options = obj2array($options);
      $e = new $entity;
      if (method_exists($e, "get_list")) {
        ob_start();
        $rtn = $e->get_list($options);
        $echoed = ob_get_contents();
        if (!$rtn && $echoed) {
          return array("error"=>$echoed);
        } else {
          if (isset($rtn["rows"])) {
            return $rtn["rows"];
          } else {
            return $rtn;
          }
        }
      } else {
        die("Entity method '".$entity."->get_list()' does not exist."); 
{'fraction_non_alphanumeric': 0.14629221732745962, 'fraction_numerical': 0.0028450807635829662, 'mean_word_length': 2.931096681096681, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506162', 'n_tokens_mistral': 3456, 'n_tokens_neox': 3367, 'n_words': 916}