';
}
@@ -256,7 +330,7 @@ switch ($action) {
if (SP_ACL::checkUserAccess("config")) {
$tplvars['active'] ++;
- echo '
';
+ echo '
';
SP_Html::getTemplate('migrate', $tplvars);
echo '
';
}
diff --git a/imgs/appmgmt.png b/imgs/appmgmt.png
new file mode 100644
index 00000000..894d1485
Binary files /dev/null and b/imgs/appmgmt.png differ
diff --git a/inc/acl.class.php b/inc/acl.class.php
index 41a8012b..9c35f8b8 100644
--- a/inc/acl.class.php
+++ b/inc/acl.class.php
@@ -71,12 +71,16 @@ class SP_ACL {
return ( $blnUIsAdminApp || $blnUIsAdminAcc || $profile->userProfile_pDelete );
case "accfiles":
return ( $blnUIsAdminApp || $blnUIsAdminAcc || $profile->userProfile_pFiles );
+ case "appmgmtmenu":
+ return ( $blnUIsAdminApp || $profile->userProfile_pAppMgmtMenu );
case "configmenu":
return ( $blnUIsAdminApp || $profile->userProfile_pConfigMenu );
case "config":
return ( $blnUIsAdminApp || $profile->userProfile_pConfig );
case "categories":
- return ( $blnUIsAdminApp || $profile->userProfile_pConfigCategories );
+ return ( $blnUIsAdminApp || $profile->userProfile_pAppMgmtCategories );
+ case "customers":
+ return ( $blnUIsAdminApp || $profile->userProfile_pAppMgmtCustomers );
case "masterpass":
return ( $blnUIsAdminApp || $profile->userProfile_pConfigMasterPass );
case "backup":
diff --git a/inc/category.class.php b/inc/category.class.php
index f22d771b..e5b8c5e7 100644
--- a/inc/category.class.php
+++ b/inc/category.class.php
@@ -5,7 +5,7 @@
*
* @author nuxsmin
* @link http://syspass.org
- * @copyright 2012 Rubén Domínguez nuxsmin@syspass.org
+ * @copyright 2014 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
@@ -23,27 +23,28 @@
* along with sysPass. If not, see
.
*
*/
-
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
/**
* Esta clase es la encargada de realizar las operaciones sobre las categorías de sysPass.
*/
class SP_Category {
+ public static $categoryName;
+ public static $categoryDescription;
public static $categoryLastId;
/**
* @brief Obtener el id de una categoría por el nombre
* @param string $categoryName con el nombre de la categoría
* @return bool|int si la consulta es errónea devuelve bool. Si no hay registros o se obtiene el id, devuelve int
- */
+ */
public static function getCategoryIdByName($categoryName) {
$query = "SELECT category_id "
. "FROM categories "
. "WHERE category_name = '" . DB::escape($categoryName) . "' LIMIT 1";
$queryRes = DB::getResults($query, __FUNCTION__);
- if ( $queryRes === FALSE ) {
+ if ($queryRes === FALSE) {
return FALSE;
}
@@ -58,19 +59,72 @@ class SP_Category {
* @brief Crear una nueva categoría en la BBDD
* @param string $categoryName con el nombre de la categoría
* @return bool
- */
- public static function categoryAdd($categoryName) {
+ */
+ public static function addCategory() {
$query = "INSERT INTO categories "
- . "SET category_name = '" . DB::escape($categoryName) . "'";
+ . "SET category_name = '" . DB::escape(self::$categoryName) . "',"
+ . "category_description = '" . DB::escape(self::$categoryDescription) . "'";
if (DB::doQuery($query, __FUNCTION__) === FALSE) {
return FALSE;
}
self::$categoryLastId = DB::$lastId;
-
+
$message['action'] = _('Nueva Categoría');
- $message['text'][] = _('Nombre') . ': ' . $categoryName;
+ $message['text'][] = _('Nombre') . ': ' . self::$categoryName;
+
+ SP_Common::wrLogInfo($message);
+ SP_Common::sendEmail($message);
+
+ return TRUE;
+ }
+
+ /**
+ * @brief Comprobar si existe una categoría duplicada
+ * @param int $id con el Id de la categoría a consultar
+ * @return bool
+ */
+ public static function checkDupCategory($id = NULL) {
+
+ if ($id === NULL) {
+ $query = "SELECT category_id "
+ . "FROM categories "
+ . "WHERE category_name = '" . DB::escape(self::$categoryName) . "'";
+ } else {
+ $query = "SELECT category_id "
+ . "FROM categories "
+ . "WHERE category_name = '" . DB::escape(self::$categoryName) . "' AND category_id <> " . $id;
+ }
+
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
+ return FALSE;
+ }
+
+ if (count(DB::$last_result) >= 1) {
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * @brief Eliminar una categoría de la BBDD
+ * @param int $id con el id de la categoría
+ * @return bool
+ */
+ public static function delCategory($id) {
+ $categoryName = self::getCategoryNameById($id);
+
+ $query = "DELETE FROM categories "
+ . "WHERE category_id = " . (int) $id . " LIMIT 1";
+
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
+ return FALSE;
+ }
+
+ $message['action'] = _('Eliminar Categoría');
+ $message['text'][] = _('Nombre') . ': ' .$categoryName.' ('. $id.')';
SP_Common::wrLogInfo($message);
SP_Common::sendEmail($message);
@@ -78,95 +132,153 @@ class SP_Category {
return TRUE;
}
- /**
- * @brief Comprobar si una categoría está en uso por alguna cuenta
- * @param int $categoryId con el id de la categoría
- * @return bool
- */
- public static function isCategoryInUse($categoryId) {
- $query = "SELECT account_categoryId "
- . "FROM accounts "
- . "WHERE account_categoryId = " . (int) $categoryId;
-
- if (DB::doQuery($query, __FUNCTION__) === FALSE) {
- return FALSE;
- }
-
- return ( count(DB::$last_result) > 0 ) ? TRUE : FALSE;
- }
-
- /**
- * @brief Eliminar una categoría de la BBDD
- * @param int $categoryId con el id de la categoría
- * @return bool
- */
- public static function categoryDel($categoryId) {
- $query = "DELETE FROM categories "
- . "WHERE category_id = $categoryId LIMIT 1";
-
- if (DB::doQuery($query, __FUNCTION__) === FALSE) {
- return FALSE;
- }
-
- return TRUE;
- }
-
/**
* @brief Actualizar una categoría en la BBDD con el id
- * @param int $categoryId con el id de la categoría
- * @param int $categoryNameNew con el nombre nuevo de la categoría
+ * @param int $id con el Id de la categoría a consultar
* @return bool
*/
- public static function editCategoryById($categoryId, $categoryNameNew) {
+ public static function updateCategory($id) {
+ $categoryName = self::getCategoryNameById($id);
+
$query = "UPDATE categories "
- . "SET category_name = '" . DB::escape($categoryNameNew) . "' "
- . "WHERE category_id = " . (int) $categoryId . " LIMIT 1";
+ . "SET category_name = '" . DB::escape(self::$categoryName) . "',"
+ . "category_description = '" . DB::escape(self::$categoryDescription) . "' "
+ . "WHERE category_id = " . (int) $id . " LIMIT 1";
if (DB::doQuery($query, __FUNCTION__) === FALSE) {
return FALSE;
}
+ $message['action'] = _('Modificar Categoría');
+ $message['text'][] = _('Nombre') . ': ' . $categoryName.' > '.self::$categoryName;
+
+ SP_Common::wrLogInfo($message);
+ SP_Common::sendEmail($message);
+
return TRUE;
}
/**
* @brief Obtiene el listado de categorías
+ * @param int $id con el Id de la categoría
+ * @param bool $retAssocArray para devolver un array asociativo
* @return array con en id de categorioa como clave y en nombre como valor
- */
- public static function getCategories(){
+ */
+ public static function getCategories($id = NULL, $retAssocArray = FALSE) {
$query = "SELECT category_id,"
- . "category_name "
- . "FROM categories "
- . "ORDER BY category_name";
+ . "category_name,"
+ . "category_description "
+ . "FROM categories ";
+
+ if (!is_null($id)) {
+ $query .= "WHERE category_id = " . (int) $id . " LIMIT 1";
+ } else {
+ $query .= "ORDER BY category_name";
+ }
+
$queryRes = DB::getResults($query, __FUNCTION__, TRUE);
- if ( $queryRes === FALSE ){
+ if ($queryRes === FALSE) {
return array();
}
-
- $resCategories = array();
-
- foreach ( $queryRes as $category ){
- $resCategories[$category->category_id] = $category->category_name;
+
+ if ($retAssocArray) {
+ $resCategories = array();
+
+ foreach ($queryRes as $category) {
+ $resCategories[$category->category_id] = $category->category_name;
+ }
+
+ return $resCategories;
}
- return $resCategories;
+ return $queryRes;
+ }
+
+ /**
+ * @brief Obtiene el nombre de la categoría a partir del Id
+ * @param int $id con el Id de la categoría a consultar
+ * @return string con el nombre de la categoría
+ */
+ public static function getCategoryNameById($id) {
+ $query = "SELECT category_name "
+ . "FROM categories "
+ . "WHERE category_id = " . (int) $id;
+ $queryRes = DB::getResults($query, __FUNCTION__);
+
+ if ($queryRes === FALSE) {
+ return FALSE;
+ }
+
+ return $queryRes->category_name;
+ }
+
+ /**
+ * @brief Obtener los datos de una categoría
+ * @param int $id con el Id de la categoría a consultar
+ * @return array con el nombre de la columna como clave y los datos como valor
+ */
+ public static function getCategoryData($id = 0) {
+ $category = array('category_id' => 0,
+ 'category_name' => '',
+ 'category_description' => '',
+ 'action' => 1);
+
+ if ($id > 0) {
+ $categories = self::getCategories($id);
+
+ if ($categories) {
+ foreach ($categories[0] as $name => $value) {
+ $category[$name] = $value;
+ }
+ $category['action'] = 2;
+ }
+ }
+
+ return $category;
}
/**
- * @brief Obtiene el nombre de la categoría a partir del Id
- * @return string con el nombre de la categoría
- */
- public static function getCategoryNameById($id){
- $query = "SELECT category_name "
- . "FROM categories "
- . "WHERE category_id = ".(int)$id;
+ * @brief Comprobar si una categoría está en uso
+ * @param int $id con el Id de la categoría a consultar
+ * @return bool
+ *
+ * Esta función comprueba si una categoría está en uso por cuentas.
+ */
+ public static function checkCategoryInUse($id) {
+
+ $numAccounts = self::getCategoriesInAccounts($id);
+
+ $out = '';
+
+ if ($numAccounts) {
+ $out[] = _('Cuentas') . " (" . $numAccounts . ")";
+ }
+
+ if (is_array($out)) {
+ return implode('
', $out);
+ }
+
+ return TRUE;
+ }
+
+ /**
+ * @brief Obtener el número de cuentas que usan una categoría
+ * @param int $id con el Id de la categoría a consultar
+ * @return integer con el número total de cuentas
+ */
+ private static function getCategoriesInAccounts($id) {
+ $query = "SELECT COUNT(*) as uses "
+ . "FROM accounts "
+ . "WHERE account_categoryId = " . (int) $id;
+
$queryRes = DB::getResults($query, __FUNCTION__);
- if ( $queryRes === FALSE ){
+ if ($queryRes === FALSE) {
return FALSE;
}
-
- return $queryRes->category_name;
+
+ return $queryRes->uses;
}
-}
\ No newline at end of file
+
+}
diff --git a/inc/customer.class.php b/inc/customer.class.php
index 9eb11594..f0b011f0 100644
--- a/inc/customer.class.php
+++ b/inc/customer.class.php
@@ -1,151 +1,280 @@
.
-*
-*/
+/**
+ * sysPass
+ *
+ * @author nuxsmin
+ * @link http://syspass.org
+ * @copyright 2014 Rubén Domínguez nuxsmin@syspass.org
+ *
+ * This file is part of sysPass.
+ *
+ * sysPass is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * sysPass 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with sysPass. If not, see
.
+ *
+ */
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
/**
* Esta clase es la encargada de realizar las operaciones sobre los clientes de sysPass
*/
-class SP_Customer{
+class SP_Customer {
- var $customerId;
- var $customerName;
- var $customerDescription;
- var $customerLastId;
- var $customerHash;
+ public static $customerName;
+ public static $customerDescription;
+ public static $customerLastId;
+ public static $customerHash;
/**
* @brief Obtener el listado de clientes
+ * @param int $customerId con el Id del cliente
+ * @param bool $retAssocArray para devolver un array asociativo
* @return array con el id de cliente como clave y el nombre como valor
- */
- public static function getCustomers(){
+ */
+ public static function getCustomers($customerId = NULL, $retAssocArray = FALSE) {
$query = "SELECT customer_id,"
- . "customer_name "
- . "FROM customers "
- . "ORDER BY customer_name";
- $queryRes = DB::getResults($query, __FUNCTION__, TRUE);
-
- if ( $queryRes === FALSE ){
- return FALSE;
- }
-
- $resCustomers = array();
-
- foreach ( $queryRes as $customer ){
- $resCustomers[$customer->customer_id] = $customer->customer_name;
+ . "customer_name, "
+ . "customer_description "
+ . "FROM customers ";
+
+ if (!is_null($customerId)) {
+ $query .= "WHERE customer_id = " . (int) $customerId . " LIMIT 1";
+ } else {
+ $query .= "ORDER BY customer_name";
}
- return $resCustomers;
+ $queryRes = DB::getResults($query, __FUNCTION__, TRUE);
+
+ if ($queryRes === FALSE) {
+ return FALSE;
+ }
+
+ if ($retAssocArray) {
+ $resCustomers = array();
+
+ foreach ($queryRes as $customer) {
+ $resCustomers[$customer->customer_id] = $customer->customer_name;
+ }
+
+ return $resCustomers;
+ }
+
+ return $queryRes;
}
-
+
/**
* @brief Crear un nuevo cliente en la BBDD
* @return bool
- */
- public function customerAdd(){
+ */
+ public static function addCustomer() {
$query = "INSERT INTO customers "
- . "SET customer_name = '".DB::escape($this->customerName)."',"
- . "customer_hash = '".$this->mkCustomerHash()."'";
-
- if ( DB::doQuery($query, __FUNCTION__) === FALSE ){
+ . "SET customer_name = '" . DB::escape(self::$customerName) . "',"
+ . "customer_hash = '" . self::mkCustomerHash() . "'";
+
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
return FALSE;
}
-
- $this->customerLastId = DB::$lastId;
-
+
+ self::$customerLastId = DB::$lastId;
+
$message['action'] = _('Nuevo Cliente');
- $message['text'][] = _('Nombre').': '.$this->customerName;
+ $message['text'][] = _('Nombre') . ': ' . self::$customerName;
+
SP_Common::wrLogInfo($message);
-
+ SP_Common::sendEmail($message);
+
+ return TRUE;
+ }
+
+ /**
+ * @brief Actualizar un cliente en la BBDD
+ * @return bool
+ */
+ public static function updateCustomer($id) {
+ $query = "UPDATE customers "
+ . "SET customer_name = '" . DB::escape(self::$customerName) . "',"
+ . "customer_description = '" . DB::escape(self::$customerDescription) . "',"
+ . "customer_hash = '" . self::mkCustomerHash() . "' "
+ . "WHERE customer_id = " . (int) $id;
+
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
+ return FALSE;
+ }
+
+ $message['action'] = _('Actualizar Cliente');
+ $message['text'][] = _('Nombre') . ': ' . self::$customerName;
+
+ SP_Common::wrLogInfo($message);
+ SP_Common::sendEmail($message);
+
return TRUE;
}
/**
* @brief Eliminar un cliente de la BBDD
+ * @param int $id con el Id del cliente a eliminar
* @return bool
- */
- public function customerDel(){
- $query = "DELETE FROM customers"
- . " WHERE customer_id = $this->customerId LIMIT 1";
-
- if ( DB::doQuery($query, __FUNCTION__) === FALSE ){
+ */
+ public static function delCustomer($id) {
+ $customerName = self::getCustomerById($id);
+
+ $query = "DELETE FROM customers "
+ . "WHERE customer_id = " . (int) $id . " LIMIT 1";
+
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
return FALSE;
}
-
+
+ $message['action'] = _('Eliminar Cliente');
+ $message['text'][] = _('Nombre') . ': ' . $customerName;
+
+ SP_Common::wrLogInfo($message);
+ SP_Common::sendEmail($message);
+
return TRUE;
}
-
+
/**
* @brief Crear un hash con el nombre del cliente
* @return string con el hash generado
*
* Esta función crear un hash para detectar clientes duplicados mediante
* la eliminación de carácteres especiales y capitalización
- */
- private function mkCustomerHash(){
- $charsSrc = array("."," ","_",",","-",";","'","\"",":","(",")","|","/");
- $newValue = strtolower(str_replace($charsSrc, '', DB::escape($this->customerName)));
+ */
+ private static function mkCustomerHash() {
+ $charsSrc = array(
+ ".", " ", "_", ", ", "-", ";
+ ", "'", "\"", ":", "(", ")", "|", "/");
+ $newValue = strtolower(str_replace($charsSrc, '', DB::escape(self::$customerName)));
$hashValue = md5($newValue);
-
- return $hashValue;
+
+ return $hashValue;
}
-
+
/**
* @brief Comprobar si existe un cliente duplicado comprobando el hash
* @return bool
- */
- public function chekDupCustomer(){
- $query = "SELECT customer_id "
- . "FROM customers "
- . "WHERE customer_hash = '".$this->mkCustomerHash()."'";
-
- if ( DB::doQuery($query, __FUNCTION__) === FALSE ){
- return FALSE;
+ */
+ public static function checkDupCustomer($id = NULL) {
+ if ($id === NULL) {
+ $query = "SELECT customer_id "
+ . "FROM customers "
+ . "WHERE customer_hash = '" . self::mkCustomerHash() . "'";
+ } else {
+ $query = "SELECT customer_id "
+ . "FROM customers "
+ . "WHERE customer_hash = '" . self::mkCustomerHash() . "' AND customer_id <> " . $id;
}
- if ( count(DB::$last_result) >= 1 ){
+ if (DB::doQuery($query, __FUNCTION__) === FALSE) {
return FALSE;
}
-
+
+ if (count(DB::$last_result) >= 1) {
+ return FALSE;
+ }
+
return TRUE;
}
-
+
/**
* @brief Obtener el Id de un cliente por su nombre
* @return int con el Id del cliente
- */
- public function getCustomerByName(){
+ */
+ public static function getCustomerByName() {
$query = "SELECT customer_id "
. "FROM customers "
- . "WHERE customer_hash = '".$this->mkCustomerHash()."' LIMIT 1";
+ . "WHERE customer_hash = '" . self::mkCustomerHash() . "' LIMIT 1";
$queryRes = DB::getResults($query, __FUNCTION__);
-
- if ( $queryRes === FALSE ){
+
+ if ($queryRes === FALSE) {
return FALSE;
}
-
+
return $queryRes->customer_id;
}
+
+ /**
+ * @brief Obtener el Nombre de un cliente por su Id
+ * @param int $id con el Id del cliente
+ * @return string con el nombre del cliente
+ */
+ public static function getCustomerById($id) {
+ $query = "SELECT customer_name "
+ . "FROM customers "
+ . "WHERE customer_id = " . (int) $id . " LIMIT 1";
+ $queryRes = DB::getResults($query, __FUNCTION__);
+
+ if ($queryRes === FALSE) {
+ return FALSE;
+ }
+
+ return $queryRes->customer_name;
+ }
+
+ /**
+ * @brief Obtener los datos de un cliente
+ * @param int $id con el Id del cliente a consultar
+ * @return array con el nombre de la columna como clave y los datos como valor
+ */
+ public static function getCustomerData($id = 0) {
+ $customer = array('customer_id' => 0,
+ 'customer_name' => '',
+ 'customer_description' => '',
+ 'action' => 1);
+
+ if ($id > 0) {
+ $customers = self::getCustomers($id);
+
+ if ($customers) {
+ foreach ($customers[0] as $name => $value) {
+ $customer[$name] = $value;
+ }
+ $customer['action'] = 2;
+ }
+ }
+
+ return $customer;
+ }
+
+ /**
+ * @brief Comprobar si un cliente está en uso
+ * @param int $id con el Id del cliente a consultar
+ * @return bool
+ *
+ * Esta función comprueba si un cliente está en uso por cuentas.
+ */
+ public static function checkCustomerInUse($id) {
+ $count['accounts'] = self::getCustomerInAccounts($id);
+ return $count;
+ }
+
+ /**
+ * @brief Obtener el número de cuentas que usan un cliente
+ * @param int $id con el Id del cliente a consultar
+ * @return integer con el número total de cuentas
+ */
+ private static function getCustomerInAccounts($id) {
+ $query = "SELECT COUNT(*) as uses "
+ . "FROM accounts "
+ . "WHERE account_customerId = " . (int) $id;
+
+ $queryRes = DB::getResults($query, __FUNCTION__);
+
+ if ($queryRes === FALSE) {
+ return FALSE;
+ }
+
+ return $queryRes->uses;
+ }
}
\ No newline at end of file
diff --git a/inc/db.class.php b/inc/db.class.php
index 6b27b752..8b72bf98 100644
--- a/inc/db.class.php
+++ b/inc/db.class.php
@@ -1,76 +1,78 @@
.
-*
-*/
+/**
+ * sysPass
+ *
+ * @author nuxsmin
+ * @link http://syspass.org
+ * @copyright 2012 Rubén Domínguez nuxsmin@syspass.org
+ *
+ * This file is part of sysPass.
+ *
+ * sysPass is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * sysPass 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with sysPass. If not, see
.
+ *
+ */
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
/**
* Esta clase es la encargada de realizar las operaciones con la BBDD de sysPass.
*/
class DB {
+
private static $_db;
-
static $last_result;
static $affected_rows;
static $lastId;
static $txtError;
static $numError;
static $num_rows;
-
- function __construct(){ }
-
+
+ function __construct() {
+
+ }
+
/**
* @brief Realizar la conexión con la BBDD
* @return bool
*
* Esta función utiliza mysqli para conectar con la base de datos.
* Guarda el objeto creado en la variable $_db de la clase
- */
- private static function connection(){
- if ( self::$_db ){
+ */
+ private static function connection() {
+ if (self::$_db) {
return true;
}
-
+
$dbhost = SP_Config::getValue("dbhost");
$dbuser = SP_Config::getValue("dbuser");
$dbpass = SP_Config::getValue("dbpass");
$dbname = SP_Config::getValue("dbname");
-
- self::$_db = @new mysqli($dbhost,$dbuser,$dbpass,$dbname);
-
- if ( self::$_db->connect_errno ){
- if ( SP_Config::getValue("installed") ){
- if ( self::$_db->connect_errno === 1049 ){
+
+ self::$_db = @new mysqli($dbhost, $dbuser, $dbpass, $dbname);
+
+ if (self::$_db->connect_errno) {
+ if (SP_Config::getValue("installed")) {
+ if (self::$_db->connect_errno === 1049) {
SP_Config::setValue('installed', '0');
}
-
- SP_Init::initError(_('No es posible conectar con la BD'),'Error '.self::$_db->connect_errno . ': '.self::$_db->connect_error);
- } else{
+
+ SP_Init::initError(_('No es posible conectar con la BD'), 'Error ' . self::$_db->connect_errno . ': ' . self::$_db->connect_error);
+ } else {
return false;
}
}
- return true;
+ return true;
}
/**
@@ -79,9 +81,9 @@ class DB {
* @return string con la cadena escapada
*
* Esta función utiliza mysqli para escapar cadenas de texto.
- */
+ */
public static function escape($str) {
- if ( self::connection() ){
+ if (self::connection()) {
return self::$_db->real_escape_string(trim($str));
} else {
return $str;
@@ -93,104 +95,137 @@ class DB {
* @param string $query con la consulta a realizar
* @param string $querySource con el nombre de la función que realiza la consulta
* @return bool|int devuleve bool si hay un error. Devuelve int con el número de registros
- */
- public static function doQuery($query,$querySource) {
- if ( ! self::connection() ){
+ */
+ public static function doQuery($query, $querySource) {
+ if (!self::connection()) {
return false;
}
-
- $isSelect = preg_match("/^.*(select|show)\s/i",$query);
+
+ $isSelect = preg_match("/^.*(select|show)\s/i", $query);
// Limpiar valores de caché
self::$last_result = array();
-
+
$queryRes = self::$_db->query($query);
- if ( ! $queryRes ) {
+ if (!$queryRes) {
self::$numError = self::$_db->errno;
self::$txtError = self::$_db->error;
-
+
$message['action'] = $querySource;
- $message['text'][] = self::$_db->error.'('.self::$_db->errno.')';
- $message['text'][] = "SQL: ".self::escape($query);
-
+ $message['text'][] = self::$_db->error . '(' . self::$_db->errno . ')';
+ $message['text'][] = "SQL: " . self::escape($query);
+
SP_Common::wrLogInfo($message);
return FALSE;
}
- if ( $isSelect ) {
- if ( $queryRes->num_rows == 1 ){
+ if ($isSelect) {
+ if ($queryRes->num_rows == 1) {
self::$last_result = @$queryRes->fetch_object();
} else {
$num_row = 0;
-
- while ( $row = @$queryRes->fetch_object() ) {
+
+ while ($row = @$queryRes->fetch_object()) {
self::$last_result[$num_row] = $row;
$num_row++;
}
}
-
+
self::$num_rows = $queryRes->num_rows;
-
+
$queryRes->close();
}
self::$lastId = self::$_db->insert_id;
$numRows = self::$_db->affected_rows;
-
+
return $numRows;
}
-
+
/**
* @brief Obtener los resultados de una consulta
* @param string $query con la consulta a realizar
* @param string $querySource con el nombre de la función que realiza la consulta
* @return bool|array devuelve bool si hay un error. Devuelve array con el array de registros devueltos
- */
+ */
public static function getResults($query, $querySource, $retArray = FALSE) {
- if ( $query ){
- self::doQuery($query,$querySource);
+ if ($query) {
+ self::doQuery($query, $querySource);
}
-
- if ( self::$numError || self::$num_rows === 0) {
+
+ if (self::$numError || self::$num_rows === 0) {
return FALSE;
}
-
- if ( is_null(self::$numError) && count(self::$last_result) === 0 ){
+
+ if (is_null(self::$numError) && count(self::$last_result) === 0) {
return TRUE;
}
- if ( $retArray === TRUE && is_object(self::$last_result) ){
+ if ($retArray === TRUE && is_object(self::$last_result)) {
return array(self::$last_result);
}
-
+
return self::$last_result;
}
/**
* @brief Comprobar que la base de datos existe
* @return bool
- */
- public static function checkDatabaseExist(){
- if ( ! self::connection() ){
+ */
+ public static function checkDatabaseExist() {
+ if (!self::connection()) {
return false;
}
-
- $query='SELECT COUNT(*) '
+
+ $query = 'SELECT COUNT(*) '
. 'FROM information_schema.tables'
- ." WHERE table_schema='".SP_Config::getValue("dbname")."' "
+ . " WHERE table_schema='" . SP_Config::getValue("dbname") . "' "
. "AND table_name = 'usrData';";
-
+
$resquery = self::$_db->query($query);
-
- if( $resquery ) {
+
+ if ($resquery) {
$row = $resquery->fetch_row();
}
-
- if( ! $resquery || $row[0] == 0) {
+
+ if (!$resquery || $row[0] == 0) {
return false;
}
-
+
return true;
}
-}
\ No newline at end of file
+
+ /**
+ * @brief Obtener los datos para generar un select
+ * @param string $tblName con el nombre de la tabla a cunsultar
+ * @param string $tblColId con el nombre de la columna a mostrar
+ * @param array $arrFilter con las columnas a filtrar
+ * @param array $arrOrder con el orden de las columnas
+ * @return array con los valores del select con el Id como clave y el nombre como valor
+ */
+ public static function getValuesForSelect($tblName, $tblColId, $tblColName, $arrFilter = '', $arrOrder = '') {
+ if (!$tblName || !$tblColId || !$tblColName) {
+ return;
+ }
+
+ $strFilter = ( is_array($arrFilter) ) ? " WHERE " . implode(" OR ", $arrFilter) : "";
+ $strOrder = ( is_array($arrOrder) ) ? " ORDER BY " . implode(",", $arrOrder) : 'ORDER BY ' . $tblColName . ' ASC';
+
+ $query = "SELECT $tblColId, $tblColName FROM $tblName $strFilter $strOrder";
+ $queryRes = self::getResults($query, __FUNCTION__);
+
+ if ($queryRes === FALSE) {
+ return FALSE;
+ }
+
+ $arrValues = array();
+
+ foreach ($queryRes as $row) {
+ $arrValues[$row->$tblColId] = $row->$tblColName;
+ }
+
+ return $arrValues;
+ }
+
+}
diff --git a/inc/dbstructure.sql b/inc/dbstructure.sql
index 63a4d6db..4b203957 100644
--- a/inc/dbstructure.sql
+++ b/inc/dbstructure.sql
@@ -26,7 +26,7 @@ CREATE TABLE `accFiles` (
`accfile_extension` varchar(10) NOT NULL,
PRIMARY KEY (`accfile_id`),
KEY `IDX_accountId` (`accfile_accountId`)
-) ENGINE=MyISAM AUTO_INCREMENT=61 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=62 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -42,7 +42,7 @@ CREATE TABLE `accGroups` (
`accgroup_groupId` int(10) unsigned NOT NULL,
PRIMARY KEY (`accgroup_id`),
KEY `IDX_accountId` (`accgroup_accountId`)
-) ENGINE=MyISAM AUTO_INCREMENT=68 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
+) ENGINE=MyISAM AUTO_INCREMENT=69 DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -77,7 +77,7 @@ CREATE TABLE `accHistory` (
`accHistory_otherGroupEdit` varchar(45) DEFAULT NULL,
PRIMARY KEY (`acchistory_id`),
KEY `IDX_accountId` (`acchistory_accountId`)
-) ENGINE=MyISAM AUTO_INCREMENT=264 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=285 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -127,7 +127,7 @@ CREATE TABLE `accounts` (
KEY `IDX_userId` (`account_userGroupId`,`account_userId`),
KEY `IDX_customerId` (`account_customerId`),
FULLTEXT KEY `IDX_searchTxt` (`account_name`,`account_login`,`account_url`,`account_notes`)
-) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=44 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -140,8 +140,9 @@ DROP TABLE IF EXISTS `categories`;
CREATE TABLE `categories` (
`category_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
`category_name` varchar(50) NOT NULL,
+ `category_description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`category_id`)
-) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf16;
+) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=utf16;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -172,7 +173,7 @@ CREATE TABLE `customers` (
`customer_description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`customer_id`),
KEY `IDX_name` (`customer_name`,`customer_hash`)
-) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -190,7 +191,7 @@ CREATE TABLE `log` (
`log_action` varchar(50) NOT NULL,
`log_description` text NOT NULL,
PRIMARY KEY (`log_id`)
-) ENGINE=MyISAM AUTO_INCREMENT=79 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=640 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -225,7 +226,7 @@ CREATE TABLE `usrData` (
PRIMARY KEY (`user_id`),
UNIQUE KEY `IDX_login` (`user_login`),
KEY `IDX_pass` (`user_pass`)
-) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -240,7 +241,7 @@ CREATE TABLE `usrGroups` (
`usergroup_name` varchar(50) NOT NULL,
`usergroup_description` varchar(255) DEFAULT NULL,
PRIMARY KEY (`usergroup_id`)
-) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -257,7 +258,6 @@ CREATE TABLE `usrProfiles` (
`userProfile_pEdit` bit(1) DEFAULT b'0',
`userProfile_pAdd` bit(1) DEFAULT b'0',
`userProfile_pConfig` bit(1) DEFAULT b'0',
- `userProfile_pConfigCategories` bit(1) DEFAULT b'0',
`userProfile_pConfigMasterPass` bit(1) DEFAULT b'0',
`userProfile_pConfigBackup` bit(1) DEFAULT b'0',
`userProfile_pUsers` bit(1) DEFAULT b'0',
@@ -271,8 +271,11 @@ CREATE TABLE `usrProfiles` (
`userProfile_pFiles` bit(1) DEFAULT b'0',
`userProfile_pConfigMenu` bit(1) DEFAULT b'0',
`userProfile_pUsersMenu` bit(1) DEFAULT b'0',
+ `userProfile_pAppMgmt` bit(1) DEFAULT b'0',
+ `userProfile_pAppMgmtCategories` bit(1) DEFAULT b'0',
+ `userProfile_pAppMgmtCustomers` bit(1) DEFAULT b'0',
PRIMARY KEY (`userprofile_id`)
-) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
+) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
@@ -282,5 +285,4 @@ CREATE TABLE `usrProfiles` (
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
diff --git a/inc/groups.class.php b/inc/groups.class.php
index 137209e2..4b11c3ef 100644
--- a/inc/groups.class.php
+++ b/inc/groups.class.php
@@ -179,35 +179,19 @@ class SP_Groups {
self::$queryLastId = DB::$lastId;
- return TRUE;
+// return TRUE;
}
/**
* @brief Comprobar si un grupo está en uso
- * @return bool
+ * @return array con el número de usuarios/cuentas que usan el grupo
*
* Esta función comprueba si un grupo está en uso por usuarios o cuentas.
*/
public static function checkGroupInUse() {
-
- $numUsers = self::getGroupInUsers();
- $numAccounts = self::getGroupInAccounts() + self::getGroupInAccountsSec();
-
- $out = '';
-
- if ($numUsers) {
- $out[] = _('Usuarios') . " (" . $numUsers . ")";
- }
-
- if ($numAccounts) {
- $out[] = _('Cuentas') . " (" . $numAccounts . ")";
- }
-
- if (is_array($out)) {
- return implode('
', $out);
- }
-
- return TRUE;
+ $count['users'] = self::getGroupInUsers();
+ $count['accounts'] = self::getGroupInAccounts() + self::getGroupInAccountsSec();
+ return $count;
}
/**
@@ -233,7 +217,7 @@ class SP_Groups {
* @return integer con el número total de cuentas
*/
private static function getGroupInAccounts() {
- $query = "SELECT COUNT(*) as uses"
+ $query = "SELECT COUNT(*) as uses "
. "FROM accounts "
. "WHERE account_userGroupId = " . (int) self::$groupId;
diff --git a/inc/html.class.php b/inc/html.class.php
index 4a4149c4..9d285e54 100644
--- a/inc/html.class.php
+++ b/inc/html.class.php
@@ -5,7 +5,7 @@
*
* @author nuxsmin
* @link http://syspass.org
- * @copyright 2012 Rubén Domínguez nuxsmin@syspass.org
+ * @copyright 2014 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
@@ -91,7 +91,7 @@ class SP_Html {
*/
public static function render($page = "main", $err = NULL) {
$data['showlogo'] = 1;
-
+
// UTF8 Headers
header("Content-Type: text/html; charset=UTF-8");
@@ -110,7 +110,7 @@ class SP_Html {
foreach (self::$htmlPage as $html) {
if (is_array($html) && array_key_exists('include', $html)) {
- self::getTemplate($html['include'],$data);
+ self::getTemplate($html['include'], $data);
} else {
echo $html . PHP_EOL;
}
@@ -146,9 +146,9 @@ class SP_Html {
self::$htmlPage[] = '
';
self::$htmlPage[] = '
' . _('Javascript es necesario para el correcto funcionamiento') . '
';
self::$htmlPage[] = '
';
-
+
self::$htmlPage[] = array('include' => $page);
-
+
self::$htmlPage[] = '
';
self::makeFooter($page);
self::$htmlPage[] = '
';
@@ -254,7 +254,7 @@ class SP_Html {
* @return string con los datos limpiados
*/
public static function sanitize(&$data) {
- if (!$data){
+ if (!$data) {
return FALSE;
}
@@ -326,7 +326,7 @@ class SP_Html {
$versionParameter = md5(implode(SP_Util::getVersion()));
$js_files = self::getJs();
-
+
foreach ($js_files as $js) {
self::$htmlPage[] = '';
}
@@ -351,10 +351,10 @@ class SP_Html {
array("src" => "js/jquery.tagsinput.js", "params" => ""),
array("src" => "js/functions.php", "params" => "&l=" . SP_Init::$LANG . "&r=" . urlencode(base64_encode(SP_Init::$WEBROOT)))
);
-
+
return $jsProp;
}
-
+
/**
* @brief Devuelve información sobre la aplicación
* @return array con las propiedades de la aplicación
@@ -444,19 +444,19 @@ class SP_Html {
exit();
}
- private static function minifier($files){
- if ( !is_array($files) ){
+ private static function minifier($files) {
+ if (!is_array($files)) {
return FALSE;
}
-
- foreach ($files as $file){
+
+ foreach ($files as $file) {
//$output_min .= file_get_contents($file['src']);
- include_once SP_Init::$SERVERROOT.'/'.$file['src'];
+ include_once SP_Init::$SERVERROOT . '/' . $file['src'];
}
-
+
//return $output_min;
}
-
+
/**
* @brief Convertir un color RGB a HEX
* @param array $rgb con color en RGB
@@ -465,11 +465,105 @@ class SP_Html {
* From: http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
*/
public static function rgb2hex($rgb) {
- $hex = "#";
- $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
- $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
- $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
+ $hex = "#";
+ $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT);
+ $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT);
+ $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT);
- return $hex; // returns the hex value including the number sign (#)
- }
-}
\ No newline at end of file
+ return $hex; // returns the hex value including the number sign (#)
+ }
+
+ /**
+ * @brief Devolver una tabla con el resultado de una consulta y acciones
+ * @param array $arrTableProp con las propiedades de la tabla
+ * @return none
+ */
+ public static function getQueryTable($arrTableProp, $queryItems) {
+ $sk = SP_Common::getSessionKey(TRUE);
+
+ echo '
';
+ echo '
';
+ echo ' ';
+ echo ' ';
+ echo '
';
+
+ if ($arrTableProp["header"]) {
+ echo '
' . $arrTableProp["header"] . '
';
+ }
+
+ echo '
';
+ }
+
+}
diff --git a/inc/import.class.php b/inc/import.class.php
index b9393d38..8d0361d4 100644
--- a/inc/import.class.php
+++ b/inc/import.class.php
@@ -136,7 +136,6 @@ class SP_Import {
$groupId = SP_Common::parseParams('s', 'ugroup', 0);
$account = new SP_Account;
- $customer = new SP_Customer;
foreach (self::$fileContent as $data) {
$fields = explode(';', $data);
@@ -147,17 +146,17 @@ class SP_Import {
list($accountName, $customerName, $categoryName, $url, $username, $password, $notes) = $fields;
- $customer->customerName = $customerName;
- if ( ! $customer->chekDupCustomer() ){
- $customerId = $customer->getCustomerByName();
+ SP_Customer::$customerName = $customerName;
+ if ( !SP_Customer::checkDupCustomer() ){
+ $customerId = SP_Customer::getCustomerByName();
} else{
- $customer->customerAdd();
- $customerId = $customer->customerLastId;
+ SP_Customer::addCustomer();
+ $customerId = SP_Customer::$customerLastId;
}
$categoryId = SP_Category::getCategoryIdByName($categoryName);
if ( $categoryId == 0 ){
- SP_Category::categoryAdd($categoryName);
+ SP_Category::addCategory($categoryName);
$categoryId = SP_Category::$categoryLastId;
}
diff --git a/inc/init.php b/inc/init.php
index 28e5d934..3c74684d 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -458,7 +458,7 @@ class SP_Init {
$update = FALSE;
$configVersion = (int) str_replace('.', '', SP_Config::getValue('version'));
$databaseVersion = (int) str_replace('.', '', SP_Config::getConfigValue('version'));
- $appVersion = (int) implode(SP_Util::getVersion());
+ $appVersion = (int) implode(SP_Util::getVersion(TRUE));
if ( $databaseVersion < $appVersion && SP_Common::parseParams('g', 'nodbupgrade', 0) === 0){
if ( SP_Upgrade::needUpgrade($appVersion) && ! self::checkMaintenanceMode(TRUE) ){
diff --git a/inc/locales/en_US/LC_MESSAGES/messages.mo b/inc/locales/en_US/LC_MESSAGES/messages.mo
index 661df5f9..fe898acc 100644
Binary files a/inc/locales/en_US/LC_MESSAGES/messages.mo and b/inc/locales/en_US/LC_MESSAGES/messages.mo differ
diff --git a/inc/migrate.class.php b/inc/migrate.class.php
index 7d958626..84013548 100644
--- a/inc/migrate.class.php
+++ b/inc/migrate.class.php
@@ -246,20 +246,19 @@ class SP_Migrate {
*/
private static function migrateCustomers() {
$customers = self::getCustomers();
- $objCustomer = new SP_Customer;
$totalRecords = count($customers);
$num = 0;
foreach ($customers as $customer) {
- $objCustomer->customerName = $customer;
+ SP_Customer::$customerName = $customer;
- if (!$objCustomer->chekDupCustomer()) {
+ if (!SP_Customer::checkDupCustomer()) {
$num++;
continue;
}
- if (!$objCustomer->customerAdd()) {
+ if (!SP_Customer::addCustomer()) {
throw new MigrateException('critical',
_('No es posible crear el cliente'),
_('Contacte con el desarrollador'));
@@ -330,7 +329,7 @@ class SP_Migrate {
*/
private static function insertAccounts($account) {
if (!is_array(self::$customersByName)) {
- $customers = SP_Customer::getCustomers();
+ $customers = SP_Customer::getCustomers(NULL,TRUE);
self::$customersByName = array_flip($customers);
}
@@ -481,7 +480,7 @@ class SP_Migrate {
*/
private static function insertAccountsHistory($accountHistory) {
if (!is_array(self::$customersByName)) {
- $customers = SP_Customer::getCustomers();
+ $customers = SP_Customer::getCustomers(NULL,TRUE);
self::$customersByName = array_flip($customers);
}
diff --git a/inc/profiles.class.php b/inc/profiles.class.php
index 4d1a63af..16211cff 100644
--- a/inc/profiles.class.php
+++ b/inc/profiles.class.php
@@ -53,9 +53,10 @@ class SP_Profiles {
'userProfile_pDelete' => 0,
'userProfile_pFiles' => 0,
'userProfile_pConfig' => 0,
- 'userProfile_pConfigCategories' => 0,
'userProfile_pConfigMasterPass' => 0,
'userProfile_pConfigBackup' => 0,
+ 'userProfile_pAppMgmtCategories' => 0,
+ 'userProfile_pAppMgmtCustomers' => 0,
'userProfile_pUsers' => 0,
'userProfile_pGroups' => 0,
'userProfile_pProfiles' => 0,
@@ -99,9 +100,10 @@ class SP_Profiles {
. 'userProfile_pDelete,'
. 'userProfile_pFiles,'
. 'userProfile_pConfig,'
- . 'userProfile_pConfigCategories,'
. 'userProfile_pConfigMasterPass,'
. 'userProfile_pConfigBackup,'
+ . 'userProfile_pAppMgmtCategories,'
+ . 'userProfile_pAppMgmtCustomers,'
. 'userProfile_pUsers,'
. 'userProfile_pGroups,'
. 'userProfile_pProfiles,'
@@ -160,7 +162,8 @@ class SP_Profiles {
*/
public static function addProfile($profileProp = '') {
$enableConfig = (int) ( $profileProp["pConfig"] || $profileProp["pConfigCat"] || $profileProp["pConfigMpw"] || $profileProp["pConfigBack"]);
- $enableusers = (int) ( $profileProp["pUsers"] || $profileProp["pGroups"] || $profileProp["pProfiles"]);
+ $enableAppMgmt = (int) ( $profileProp["pAppMgmt"] || $profileProp["pAppMgmtCat"] || $profileProp["pAppMgmtCust"]);
+ $enableUsers = (int) ( $profileProp["pUsers"] || $profileProp["pGroups"] || $profileProp["pProfiles"]);
$query = "INSERT INTO usrProfiles SET "
. "userprofile_name = '" . DB::escape(self::$profileName) . "',"
@@ -174,10 +177,12 @@ class SP_Profiles {
. "userProfile_pFiles = " . $profileProp["pAccFiles"] . ","
. "userProfile_pConfigMenu = " . $enableConfig . ","
. "userProfile_pConfig = " . $profileProp["pConfig"] . ","
- . "userProfile_pConfigCategories = " . $profileProp["pConfigCat"] . ","
. "userProfile_pConfigMasterPass = " . $profileProp["pConfigMpw"] . ","
. "userProfile_pConfigBackup = " . $profileProp["pConfigBack"] . ","
- . "userProfile_pUsersMenu = " . $enableusers . ","
+ . "userProfile_pAppMgmtMenu = " . $enableAppMgmt . ","
+ . "userProfile_pAppMgmtCategories = " . $profileProp["pAppMgmtCat"] . ","
+ . "userProfile_pAppMgmtCustomers = " . $profileProp["pAppMgmtCust"] . ","
+ . "userProfile_pUsersMenu = " . $enableUsers . ","
. "userProfile_pUsers = " . $profileProp["pUsers"] . ","
. "userProfile_pGroups = " . $profileProp["pGroups"] . ","
. "userProfile_pProfiles = " . $profileProp["pProfiles"] . ","
@@ -198,7 +203,8 @@ class SP_Profiles {
*/
public static function updateProfile($profileProp = '') {
$enableConfig = (int) ( $profileProp["pConfig"] || $profileProp["pConfigCat"] || $profileProp["pConfigMpw"] || $profileProp["pConfigBack"]);
- $enableusers = (int) ( $profileProp["pUsers"] || $profileProp["pGroups"] || $profileProp["pProfiles"]);
+ $enableAppMgmt = (int) ( $profileProp["pAppMgmt"] || $profileProp["pAppMgmtCat"] || $profileProp["pAppMgmtCust"]);
+ $enableUsers = (int) ( $profileProp["pUsers"] || $profileProp["pGroups"] || $profileProp["pProfiles"]);
$query = "UPDATE usrProfiles SET "
. "userprofile_name = '" . DB::escape(self::$profileName) . "',"
@@ -212,10 +218,12 @@ class SP_Profiles {
. "userProfile_pFiles = " . $profileProp["pAccFiles"] . ","
. "userProfile_pConfigMenu = " . $enableConfig . ","
. "userProfile_pConfig = " . $profileProp["pConfig"] . ","
- . "userProfile_pConfigCategories = " . $profileProp["pConfigCat"] . ","
. "userProfile_pConfigMasterPass = " . $profileProp["pConfigMpw"] . ","
. "userProfile_pConfigBackup = " . $profileProp["pConfigBack"] . ","
- . "userProfile_pUsersMenu = " . $enableusers . ","
+ . "userProfile_pAppMgmtMenu = " . $enableAppMgmt . ","
+ . "userProfile_pAppMgmtCategories = " . $profileProp["pAppMgmtCat"] . ","
+ . "userProfile_pAppMgmtCustomers = " . $profileProp["pAppMgmtCust"] . ","
+ . "userProfile_pUsersMenu = " . $enableUsers . ","
. "userProfile_pUsers = " . $profileProp["pUsers"] . ","
. "userProfile_pGroups = " . $profileProp["pGroups"] . ","
. "userProfile_pProfiles = " . $profileProp["pProfiles"] . ","
@@ -253,20 +261,8 @@ class SP_Profiles {
* @return mixed string con el número de usuarios, o bool si no está en uso
*/
public static function checkProfileInUse() {
-
- $numUsers = self::getProfileInUsers();
-
- $out = '';
-
- if ($numUsers) {
- $out[] = _('Usuarios') . " (" . $numUsers . ")";
- }
-
- if (is_array($out)) {
- return implode('
', $out);
- }
-
- return TRUE;
+ $count['users'] = self::getProfileInUsers();
+ return $count;
}
/**
@@ -330,9 +326,10 @@ class SP_Profiles {
. "userProfile_pFiles,"
. "userProfile_pConfigMenu,"
. "userProfile_pConfig,"
- . "userProfile_pConfigCategories,"
. "userProfile_pConfigMasterPass,"
. "userProfile_pConfigBackup,"
+ . 'userProfile_pAppMgmtCategories,'
+ . 'userProfile_pAppMgmtCustomers,'
. "userProfile_pUsersMenu,"
. "userProfile_pUsers,"
. "userProfile_pGroups,"
diff --git a/inc/tpl/accounts.php b/inc/tpl/accounts.php
index ec8dbb58..0558f329 100644
--- a/inc/tpl/accounts.php
+++ b/inc/tpl/accounts.php
@@ -181,7 +181,7 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
@@ -197,7 +197,7 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
category_name;
}
@@ -267,7 +267,9 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
$otherUserId) {
+ $users = array_flip(DB::getValuesForSelect('usrData', 'user_id', 'user_name'));
+
+ foreach ( $users as $otherUserName => $otherUserId) {
$userSelected = '';
if ($otherUserId != $accountData->account_userGroupId && $otherUserId != $userId) {
@@ -292,7 +294,9 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
$groupId) {
+ $groups = array_flip(DB::getValuesForSelect('usrGroups', 'usergroup_id', 'usergroup_name'));
+
+ foreach ($groups as $groupName => $groupId) {
$uGroupSelected = '';
if ($groupId != $accountData->account_userGroupId && $groupId != $userGroupId) {
@@ -394,7 +398,7 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
- user_name; ?>
+ user_name) ? $accountData->user_name : _('N/D'); ?>
@@ -450,7 +454,7 @@ $maxFileSize = round(SP_Config::getValue('allowed_size') / 1024, 1);
- user_editName; ?>
+ user_editName) ? $accountData->user_editName : _('N/D'); ?>
diff --git a/inc/tpl/categories.php b/inc/tpl/categories.php
index 9c6ddfcc..7f05d0d3 100644
--- a/inc/tpl/categories.php
+++ b/inc/tpl/categories.php
@@ -4,7 +4,7 @@
*
* @author nuxsmin
* @link http://syspass.org
- * @copyright 2012 Rubén Domínguez nuxsmin@syspass.org
+ * @copyright 2014 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
@@ -25,89 +25,42 @@
defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
-$action = $data['action'];
+$category = SP_Category::getCategoryData($data['itemid']);
$activeTab = $data['active'];
-
-SP_ACL::checkUserAccess($action) || SP_Html::showCommonError('unavailable');
-
-$categoriesSelProp1 = array ( "name" => "categoryId",
- "id" => "sel-edit_categories",
- "class" => "",
- "size" => 1,
- "label" => "",
- "selected" => "",
- "default" => "",
- "js" => "",
- "attribs" => "");
-
-$categoriesSelProp2 = array ( "name" => "categoryId",
- "id" => "sel-del_categories",
- "class" => "",
- "size" => 1,
- "label" => "",
- "selected" => "",
- "default" => "",
- "js" => "",
- "attribs" => "");
-
-$skey = SP_Common::getSessionKey(TRUE);
?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/inc/tpl/customers.php b/inc/tpl/customers.php
new file mode 100644
index 00000000..d3c3a0a1
--- /dev/null
+++ b/inc/tpl/customers.php
@@ -0,0 +1,66 @@
+.
+ *
+ */
+
+defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'));
+
+$customer = SP_Customer::getCustomerData($data['itemid']);
+$activeTab = $data['active'];
+?>
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/inc/tpl/groups.php b/inc/tpl/groups.php
index b978c632..672c09af 100644
--- a/inc/tpl/groups.php
+++ b/inc/tpl/groups.php
@@ -59,7 +59,7 @@ $activeTab = $data['active'];
-
+
\ No newline at end of file
diff --git a/inc/tpl/main.php b/inc/tpl/main.php
index 880a6d41..841a4806 100644
--- a/inc/tpl/main.php
+++ b/inc/tpl/main.php
@@ -52,6 +52,7 @@ $chpass = ( ! isset($_SESSION['uisldap']) || $_SESSION['uisldap'] == 0 ) ? ' 'accsearch', 'title' => _('Buscar'), 'img' => 'search.png', 'checkaccess' => 0),
array('name' => 'accnew', 'title' => _('Nueva Cuenta'), 'img' => 'add.png', 'checkaccess' => 1),
array('name' => 'usersmenu', 'title' => _('Gestión de Usuarios'), 'img' => 'users.png', 'checkaccess' => 1),
+ array('name' => 'appmgmtmenu', 'title' => _('Gestión de Clientes y Categorías'), 'img' => 'appmgmt.png', 'checkaccess' => 0),
array('name' => 'configmenu', 'title' => _('Configuración'), 'img' => 'config.png', 'checkaccess' => 1),
array('name' => 'eventlog', 'title' => _('Registro de Eventos'), 'img' => 'log.png', 'checkaccess' => 1)
);
diff --git a/inc/tpl/profiles.php b/inc/tpl/profiles.php
index 6ec16664..2a18f306 100644
--- a/inc/tpl/profiles.php
+++ b/inc/tpl/profiles.php
@@ -72,11 +72,9 @@ $activeTab = $data['active'];
/>
-
- />
-
/>
+
/>
@@ -93,6 +91,11 @@ $activeTab = $data['active'];
/>
+
+ />
+
+
+ />
@@ -126,7 +129,7 @@ $activeTab = $data['active'];
-
+
\ No newline at end of file
diff --git a/inc/tpl/search.php b/inc/tpl/search.php
index 209e4ac0..5f3c0e58 100644
--- a/inc/tpl/search.php
+++ b/inc/tpl/search.php
@@ -68,8 +68,8 @@ $searchOrder = SP_Common::parseParams('s', 'accountSearchOrder', 0);
diff --git a/inc/tpl/users.php b/inc/tpl/users.php
index f3deb37c..eb0145ae 100644
--- a/inc/tpl/users.php
+++ b/inc/tpl/users.php
@@ -96,14 +96,14 @@ $ro = ( $user['checks']['user_isLdap'] ) ? "READONLY" : "";
@@ -203,7 +203,7 @@ $ro = ( $user['checks']['user_isLdap'] ) ? "READONLY" : "";
diff --git a/inc/upgrade.class.php b/inc/upgrade.class.php
index 7ed6b92a..33418868 100644
--- a/inc/upgrade.class.php
+++ b/inc/upgrade.class.php
@@ -30,7 +30,7 @@ defined('APP_ROOT') || die(_('No es posible acceder directamente a este archivo'
*/
class SP_Upgrade {
private static $result = array();
- private static $upgrade = array(110);
+ private static $upgrade = array(110,1121);
/**
* @brief Inicia el proceso de actualización de la BBDD
@@ -75,6 +75,10 @@ class SP_Upgrade {
$queries[] = "ALTER TABLE `accHistory` ADD COLUMN `accHistory_otherUserEdit` BIT NULL AFTER `acchistory_mPassHash`, ADD COLUMN `accHistory_otherGroupEdit` VARCHAR(45) NULL AFTER `accHistory_otherUserEdit`;";
$queries[] = "ALTER TABLE `accFiles` CHANGE COLUMN `accfile_type` `accfile_type` VARCHAR(100) NOT NULL ;";
break;
+ case 1121:
+ $queries[] = "ALTER TABLE `categories` ADD COLUMN `category_description` VARCHAR(255) NULL AFTER `category_name`;";
+ $queries[] = "ALTER TABLE `usrProfiles` ADD COLUMN `userProfile_pAppMgmtMenu` BIT(1) NULL DEFAULT b'0' AFTER `userProfile_pUsersMenu`,CHANGE COLUMN `userProfile_pConfigCategories` `userProfile_pAppMgmtCategories` BIT(1) NULL DEFAULT b'0' AFTER `userProfile_pAppMgmtMenu`,ADD COLUMN `userProfile_pAppMgmtCustomers` BIT(1) NULL DEFAULT b'0' AFTER `userProfile_pAppMgmtCategories`;";
+ break;
default :
self::$result['text'][] = _('No es necesario actualizar la Base de Datos.');
return TRUE;
diff --git a/inc/users.class.php b/inc/users.class.php
index 268ef454..bf2845f0 100644
--- a/inc/users.class.php
+++ b/inc/users.class.php
@@ -172,136 +172,6 @@ class SP_Users {
return $queryRes;
}
- /**
- * @brief Obtener los datos para generar un select
- * @param string $tblName con el nombre de la tabla a cunsultar
- * @param string $tblColId con el nombre de la columna a mostrar
- * @param array $arrFilter con las columnas a filtrar
- * @return array con los valores del select con el Id como clave y el nombre como valor
- */
- public static function getValuesForSelect($tblName, $tblColId, $tblColName, $arrFilter = "") {
- if (!$tblName || !$tblColId || !$tblColName) {
- return;
- }
-
- $strFilter = ( is_array($arrFilter) ) ? " WHERE " . implode(" OR ", $arrFilter) : "";
-
- $query = "SELECT $tblColId, $tblColName FROM $tblName $strFilter";
- $queryRes = DB::getResults($query, __FUNCTION__);
-
- if ($queryRes === FALSE) {
- return FALSE;
- }
-
- $arrValues = array();
-
- foreach ($queryRes as $row) {
- $arrValues[$row->$tblColId] = $row->$tblColName;
- }
-
- return $arrValues;
- }
-
- /**
- * @brief Devolver la tabla de usuarios, grupos o perfiles
- * @param array $arrUsersTableProp con las propiedades de la tabla
- * @return none
- */
- public static function getUsrGrpTable($arrUsersTableProp, $queryItems = NULL) {
- $sk = SP_Common::getSessionKey(TRUE);
-
- echo '
' . $arrUsersTableProp["header"] . '
';
- }
-
/**
* @brief Obtener los datos de un usuario
* @param int $id con el Id del usuario a consultar
@@ -965,25 +835,4 @@ class SP_Users {
return TRUE;
}
-
- /**
- * @brief Obtiene el listado de usuarios
- * @return array con los registros con nombre de usuario como clave e id de usuario como valor
- */
- public static function getUsersIdName(){
- $query = "SELECT user_id,"
- . "user_name "
- . "FROM usrData";
- $queryRes = DB::getResults($query, __FUNCTION__, TRUE);
-
- if ( $queryRes === FALSE ){
- return FALSE;
- }
-
- foreach ( $queryRes as $users ){
- $arrUsers[$users->user_name] = $users->user_id;
- }
-
- return $arrUsers;
- }
}
\ No newline at end of file
diff --git a/inc/util.class.php b/inc/util.class.php
index f20c5fbe..e099a68a 100644
--- a/inc/util.class.php
+++ b/inc/util.class.php
@@ -168,8 +168,15 @@ class SP_Util {
* @brief Devuelve la versión de sysPass
* @return array con el número de versión
*/
- public static function getVersion() {
- return array(1, 1, 02);
+ public static function getVersion($retBuild = FALSE) {
+ $build = 1;
+ $version = array(1, 1, 2);
+
+ if ( $retBuild ){
+ array_push($version, $build);
+ }
+
+ return $version;
}
/**
diff --git a/js/functions.js b/js/functions.js
index 3b4e6759..dd7a41c7 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -654,58 +654,8 @@ function importFile(sk){
});
}
-// Función para mostrar los registros de usuarios y grupos
-function usersData(id, type, sk, active, view){
- var data = {'id' : id, 'type' : type, 'sk' : sk, 'active' : active, 'view' : view, 'is_ajax' : 1};
- var url = APP_ROOT + '/ajax/ajax_usersMgmt.php';
-
- $.fancybox.showLoading();
-
- $.ajax({
- type: 'POST',
- dataType: 'html',
- url: url,
- data: data,
- success: function(response){
- $.fancybox(response,{
- padding: [0,10,10,10],
- afterClose: function(){doAction('usersmenu','',active);}
- });
- },
- error:function(jqXHR, textStatus, errorThrown){
- var txt = LANG[1] + '
';
- resMsg("error", txt);
- },
- complete: function(){$.fancybox.hideLoading();}
- });
-}
-
-// Función para editar los registros de usuarios y grupos
-function usersMgmt(frmId, isDel, id, type, sk){
- var data;
- var url = '/ajax/ajax_usersSave.php';
-
- if ( isDel === 1 ){
- var data = {'id' : id, 'type' : type, 'action' : 4, 'sk' : sk };
- var atext = '
';
- var active = frmId;
-
- alertify.confirm(atext, function (e) {
- if (e) {
- usersAjax(data, url);
- doAction('usersmenu','',active)
- }
- });
- } else {
- data = $("#" + frmId).serialize();
- //type = parseInt($('input:[name=type]').val());
-
- usersAjax(data, url);
- }
-}
-
-// Función para realizar la petición ajax de gestión de usuarios
-function usersAjax(data, url){
+// Función para realizar la petición ajax
+function sendAjax(data, url){
$.fancybox.showLoading();
$.ajax({
@@ -772,6 +722,55 @@ function usrUpdPass(id,usrlogin){
});
}
+// Función para mostrar los datos de un registro
+function appMgmtData(id, type, sk, active, view, nextaction){
+ var data = {'id' : id, 'type' : type, 'sk' : sk, 'active' : active, 'view' : view, 'is_ajax' : 1};
+ var url = APP_ROOT + '/ajax/ajax_appMgmtData.php';
+
+ $.fancybox.showLoading();
+
+ $.ajax({
+ type: 'POST',
+ dataType: 'html',
+ url: url,
+ data: data,
+ success: function(response){
+ $.fancybox(response,{
+ padding: [0,10,10,10],
+ afterClose: function(){doAction(nextaction,'',active);}
+ });
+ },
+ error:function(jqXHR, textStatus, errorThrown){
+ var txt = LANG[1] + '
';
+ resMsg("error", txt);
+ },
+ complete: function(){$.fancybox.hideLoading();}
+ });
+}
+
+// Función para editar los datos de un registro
+function appMgmtSave(frmId, isDel, id, type, sk, nextaction){
+ var data;
+ var url = '/ajax/ajax_appMgmtSave.php';
+
+ if ( isDel === 1 ){
+ var data = {'id' : id, 'type' : type, 'action' : 4, 'sk' : sk };
+ var atext = '
';
+ var active = frmId;
+
+ alertify.confirm(atext, function (e) {
+ if (e) {
+ sendAjax(data, url);
+ doAction(nextaction,'',active)
+ }
+ });
+ } else {
+ data = $("#" + frmId).serialize();
+
+ sendAjax(data, url);
+ }
+}
+
// Función para verificar si existen actualizaciones
function checkUpds(){
$.ajax({