/**
  * Sets the packaging unit for a specific distributor.
  * 
  * For example, some distributors only sell resistors in packs of 100, so you can't order just one. We use the
  * packagingUnit to calculate how many pieces will be delivered once ordered. So if your stock level falls below
  * the minimum (example: you would need to order 10 resistors), we suggest that you only order one resistor pack
  * instead of 10.
  *   
  * @param int $packagingUnit The amount of items in one package
  * @throws \PartKeepr\Part\OutOfRangeException When the packaging unit is less than 1
  */
 public function setPackagingUnit($packagingUnit)
 {
     $packagingUnit = intval($packagingUnit);
     if ($packagingUnit < 1) {
         $exception = new OutOfRangeException(PartKeepr::i18n("Packaging Unit is out of range"));
         $exception->setDetail(PartKeepr::i18n("The packaging unit must be 1 or higher"));
         throw $exception;
     }
     $this->packagingUnit = $packagingUnit;
 }
 /**
  * Processes data via HTTP POST. Reads php://input and creates a temporary image out of it.
  */
 public function uploadCam()
 {
     $tempFile = tempnam("/tmp", "PWC") . ".jpg";
     $result = file_put_contents($tempFile, file_get_contents('php://input'));
     $image = new TempUploadedFile();
     $image->replace($tempFile);
     $image->setOriginalFilename(sprintf(PartKeepr::i18n("Cam photo of %s"), date("Y-m-d H:i:s")) . ".jpg");
     PartKeepr::getEM()->persist($image);
     PartKeepr::getEM()->flush();
     return array("id" => $image->getId(), "extension" => $image->getExtension(), "size" => $image->getSize(), "originalFilename" => $image->getOriginalFilename());
 }
 /**
  * Method decodes the incoming string and returns the JSON decoded array if
  * everything was fine. If a syntax error was detected, it throws an exception.
  * 
  * @param string $string
  * @throws InvalidArgumentException
  */
 public static function decode($string)
 {
     $jsonDecoded = json_decode(trim($string), true);
     if ($jsonDecoded === null) {
         if (strlen($string) == 0) {
             $jsonDecoded = array();
         } else {
             throw new InvalidArgumentException(PartKeepr::i18n('Extended rendering configuration contains an error!'));
         }
     }
     return $jsonDecoded;
 }
 public function changePassword()
 {
     if (Configuration::getOption("partkeepr.frontend.allow_password_change", true) === false) {
         throw new \Exception("Password changing has been disabled on this server");
     }
     if (!$this->getUser()->compareHashedPassword($this->getParameter("oldpassword"))) {
         throw new \Exception("Invalid Password");
     } else {
         $this->getUser()->setHashedPassword($this->getParameter("newpassword"));
     }
     return array("data" => PartKeepr::i18n("Password changed successfully"));
 }
 /**
  * Deletes the footprint with the given id.
  * 
  * @param int $id The footprint id to delete
  * @throws \PartKeepr\Util\SerializableException
  */
 public function deleteFootprint($id)
 {
     $footprint = Footprint::loadById($id);
     try {
         PartKeepr::getEM()->remove($footprint);
         PartKeepr::getEM()->flush();
     } catch (\PDOException $e) {
         if ($e->getCode() == "23000") {
             $exception = new SerializableException(sprintf(PartKeepr::i18n("Footprint %s is in use by some parts!"), $footprint->getName()));
             $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the footprint %s, but there are parts which use this footprint."), $footprint->getName()));
             throw $exception;
         }
     }
 }
 /**
  * Creates multiple storage locations at once. 
  * 
  * Requires that the parameter "storageLocations" is set to an array with the names of the storage locations.
  * Returns all error messages as "data" index in the result array.
  */
 public function massCreate()
 {
     $this->requireParameter("storageLocations");
     $aMessages = array();
     foreach ($this->getParameter("storageLocations") as $storageLocation) {
         try {
             $obj = StorageLocationManager::getInstance()->getStorageLocationByName($storageLocation);
             $aMessages[] = sprintf(PartKeepr::i18n("Storage Location %s already exists"), $storageLocation);
         } catch (\Exception $e) {
             $obj = new StorageLocation();
             $obj->setName($storageLocation);
             PartKeepr::getEM()->persist($obj);
         }
     }
     PartKeepr::getEM()->flush();
     return array("data" => $aMessages);
 }
 /**
  * Sets up the default part unit if none exists
  */
 public function run()
 {
     $dql = "SELECT COUNT(p) FROM PartKeepr\\Part\\PartUnit p WHERE p.is_default = :default";
     $query = $this->entityManager->createQuery($dql);
     $query->setParameter("default", true);
     if ($query->getSingleScalarResult() == 0) {
         $partUnit = new PartUnit();
         $partUnit->setName(PartKeepr::i18n("Pieces"));
         $partUnit->setShortName(PartKeepr::i18n("pcs"));
         $partUnit->setDefault(true);
         $this->entityManager->persist($partUnit);
         $this->entityManager->flush();
         $this->logMessage("Added default part unit");
     } else {
         $this->logMessage("Skipped adding default part unit, because a default part unit already exists");
     }
 }
 /**
  * Deletes the given category ID.
  * @param $id int The category id to delete
  * @throws CategoryNotFoundException If the category wasn't found
  */
 public function deleteCategory($id)
 {
     $category = $this->getCategory($id);
     try {
         if ($category->hasChildren()) {
             $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains other categories."), $category->getNode()->getName()));
             $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains other categories. Please move the categories or delete them first."), $category->getNode()->getName()));
             throw $exception;
         }
         parent::deleteCategory($id);
     } catch (\PDOException $e) {
         if ($e->getCode() == "23000") {
             $exception = new SerializableException(sprintf(PartKeepr::i18n("Category '%s' contains parts."), $category->getNode()->getName()));
             $exception->setDetail(sprintf(PartKeepr::i18n("You tried to delete the category '%s', but it still contains parts. Please move the parts to another category."), $category->getNode()->getName()));
             throw $exception;
         } else {
             throw $e;
         }
     }
 }
 public function __construct()
 {
     parent::__construct(PartKeepr::i18n("Username or Password wrong."));
 }
 /**
  * Checks if the path where the file should be stored has sufficient permissions to do so.
  * 
  * @throws SerializableException
  */
 public function checkPermissions()
 {
     if (!is_writable($this->getFilePath())) {
         throw new SerializableException(sprintf(PartKeepr::i18n("Unable to write to directory %s"), $this->getFilePath()));
     }
 }
Exemple #11
0
 /**
  * Checks against the versions at partkeepr.org.
  * 
  * If a newer version was found, create a system notice entry.
  */
 public static function doVersionCheck()
 {
     $data = file_get_contents("http://www.partkeepr.org/versions.json");
     $versions = json_decode($data, true);
     if (PartKeeprVersion::PARTKEEPR_VERSION == "{V_GIT}") {
         return;
     }
     if (substr(PartKeeprVersion::PARTKEEPR_VERSION, 0, 17) == "partkeepr-nightly") {
         return;
     }
     if (version_compare(PartKeepr::getVersion(), $versions[0]["version"], '<')) {
         SystemNoticeManager::getInstance()->createUniqueSystemNotice("PARTKEEPR_VERSION_" . $versions[0]["version"], sprintf(PartKeepr::i18n("New PartKeepr Version %s available"), $versions[0]["version"]), sprintf(PartKeepr::i18n("PartKeepr Version %s changelog:"), $versions[0]["version"]) . "\n\n" . $versions[0]["changelog"]);
     }
 }
 /**
  * Constructs the exception
  * @param BaseEntity $entity
  */
 public function __construct(Part $part)
 {
     parent::__construct(PartKeepr::i18n("Part %s has no category assigned", $part));
 }
Exemple #13
0
    $aPreferences = array();
    foreach ($user->getPreferences() as $result) {
        $aPreferences[] = $result->serialize();
    }
    $aParameters["userPreferences"] = array("response" => array("data" => $aPreferences));
}
\Twig_Autoloader::register();
$loader = new \Twig_Loader_Filesystem(dirname(__FILE__) . '/templates/');
$twig = new \Twig_Environment($loader);
/* Information about maximum upload sizes */
$maxPostSize = PartKeepr::getBytesFromHumanReadable(ini_get("post_max_size"));
$maxFileSize = PartKeepr::getBytesFromHumanReadable(ini_get("upload_max_filesize"));
$aParameters["maxUploadSize"] = min($maxPostSize, $maxFileSize);
if (!class_exists("Imagick")) {
    $template = $twig->loadTemplate("error.tpl");
    echo $template->render(array("title" => PartKeepr::i18n("ImageMagick is not installed"), "error" => PartKeepr::i18n("You are missing the ImageMagick extension. Please install it and restart the setup to verify that the library was installed correctly.")));
    exit;
}
/* ImageMagick formats */
$imagick = new \Imagick();
$aParameters["availableImageFormats"] = $imagick->queryFormats();
/* Automatic Login */
if (Configuration::getOption("partkeepr.frontend.autologin.enabled", false) === true) {
    $aParameters["autoLoginUsername"] = Configuration::getOption("partkeepr.frontend.autologin.username");
    $aParameters["autoLoginPassword"] = Configuration::getOption("partkeepr.frontend.autologin.password");
}
if (Configuration::getOption("partkeepr.frontend.motd", false) !== false) {
    $aParameters["motd"] = Configuration::getOption("partkeepr.frontend.motd");
}
/* Load and render the template */
$template = $twig->loadTemplate("index.tpl");
 public function __construct($username)
 {
     parent::__construct(sprintf(PartKeepr::i18n("The user %s doesn't exist. Maybe the user was already deleted."), $username));
 }
 public function __construct()
 {
     parent::__construct(PartKeepr::i18n("Storage Location not found."));
 }
Exemple #16
0
 /**
  * Tests for APC. Throws an exception if APC is missing or not active.
  * @throws \Exception
  */
 public function testAPC()
 {
     if (!extension_loaded("apc")) {
         throw new \Exception(PartKeepr::i18n("The extension 'apc' is not loaded. Make sure that it is installed (see http://php.net/manual/en/apc.installation.php) and that it is enabled (set apc.enabled=1 in your php.ini)."));
     }
 }
 public function __construct(User $user, $preferenceKey)
 {
     $message = sprintf(PartKeepr::i18n("User preference %s not found for user %s (%s)"), $preferenceKey, $user->getUsername(), $user->getId());
     parent::__construct($message);
 }
 public function __construct($detailedReason, $requestedClass, $availableClasses)
 {
     parent::__construct(PartKeepr::i18n("No adequate renderer found: {$detailedReason} \nRequested: {$requestedClass} \nAvailable: " . implode(", ", $availableClasses)));
 }
 public function __construct($username)
 {
     parent::__construct(sprintf(PartKeepr::i18n("User %s already exists."), $username));
 }
 public function __construct($id)
 {
     parent::__construct(sprintf(PartKeepr::i18n("Category %d not found."), $id));
 }
Exemple #21
0
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Util.Serializable::serialize()
  */
 public function serialize()
 {
     return array("id" => $this->getId(), "part_name" => $this->getPart()->getName(), "part_id" => $this->getPart()->getId(), "storageLocation_name" => $this->getPart()->getStorageLocation()->getName(), "username" => is_object($this->getUser()) ? $this->getUser()->getUsername() : PartKeepr::i18n("Unknown User"), "user_id" => is_object($this->getUser()) ? $this->getUser()->getId() : null, "stockLevel" => abs($this->getStockLevel()), "comment" => $this->getComment(), "dateTime" => $this->getDateTime()->format("Y-m-d H:i:s"), "direction" => $this->getStockLevel() < 0 ? "out" : "in", "price" => $this->getPrice());
 }
Exemple #22
0
 /**
  * Set the minimum stock level for this part
  * 
  * Only positive values are allowed.
  * 
  * @param int $minStockLevel A minimum stock level, only values >= 0 are allowed. 
  * @throws \PartKeepr\Util\Exceptions\OutOfRangeException If the passed stock level is not in range (>=0)
  */
 public function setMinStockLevel($minStockLevel)
 {
     $minStockLevel = intval($minStockLevel);
     if ($minStockLevel < 0) {
         $exception = new OutOfRangeException(PartKeepr::i18n("Minimum Stock Level is out of range"));
         $exception->setDetail(PartKeepr::i18n("The minimum stock level must be 0 or higher"));
         throw $exception;
     }
     $this->minStockLevel = $minStockLevel;
 }
 public function __construct($class, $id)
 {
     parent::__construct(sprintf(PartKeepr::i18n("The object of type %s with the id %s could not be found in the database."), $class, $id));
 }
 public function __construct($class, $id)
 {
     parent::__construct(sprintf(PartKeepr::i18n("The entity %s with the id %d could not be found"), $class, $id));
 }
 /**
  * Constructs the exception
  * @param BaseEntity $entity
  */
 public function __construct()
 {
     parent::__construct(PartKeepr::i18n("No storage location assigned"));
 }