diff --git a/.gitignore b/.gitignore index 0f2d6dd..e6dcd58 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ Thumbs.db ._* .idea -.vagrant \ No newline at end of file +.vagrant +*~ +.snapshot +Secrets.php diff --git a/dbup-local.sh b/dbup-local.sh new file mode 100644 index 0000000..791f7f4 --- /dev/null +++ b/dbup-local.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +select opt in "Dump" "Load" "Cancel"; do + case $opt in + Dump ) sudo bash /var/www/mysqldump.sh; break;; + Load ) sudo bash /var/www/mysqlload.sh; break;; + Cancel ) exit;; + esac +done + diff --git a/devel-notes.txt b/devel-notes.txt new file mode 100644 index 0000000..6d0fea4 --- /dev/null +++ b/devel-notes.txt @@ -0,0 +1,111 @@ + ISLE Database Schema: + +17 TABLES: + +assets - An instance of an asset_model. + id = INT(10) + model = INT(10): id of asset_models + location = INT(10): id of locations + serial = VARCHAR(255) + notes = VARCHAR(255) + +asset_models - + id = INT(10) + mfr = INT(10) + model = VARCHAR(255) + desc = VARCHAR(255) + series = VARCHAR(255) + url = VARCHAR(255) + img = CHAR(3) + img_modified = DATETIME + +manufacturers - + id = INT(10) + name = VARCHAR(255) + url = VARCHAR(255) + parent = INT(10): id of manufacturers <=- UNUSED? + +locations - + id = INT(10) + center = VARCHAR(255) + bldg = VARCHAR(255) + room = VARCHAR(255) + +categories - Hierarchical, used to tag models. + id = INT(10) + name = VARCHAR(255) + parent = INT(10): id of category + +attributes - Can be added to model, but not asset. + id = INT(10) + name = VARCHAR(255) + type = INT(10): id of attribute_type + +relations - Can connect models, but not assets. + id = INT(10) + name = VARCHAR(255) + +users - + id = INT(10) + uid = INT(9) + name = VARCHAR(255) + email = VARCHAR(255) + role = INT(10): id of role + +asset_attachments - Join table? + id = INT(10) + name = VARCHAR(255) + asset = INT(10): id of assets + num = INT(10) + extension = VARCHAR(4) + +attribute_types - + id = INT(10) + unit = VARCHAR(255) + abbr = VARCHAR(255) + parent = INT(10): id of attribute_type + +asset_model_attributes - Join table of asset_models & attributes + id = INT(10) + model = INT(10): id of asset_model + attribute = INT(10): id of attribute + value = VARCHAR(255) + +asset_model_categories - Join table of asset_models & categories + id = INT(10) + model = INT(10): id of asset_model + category = INT(10): id of category + +asset_model_attachments - Join table of asset_models & ? + id = INT(10) + name = VARCHAR(255) + model = INT(10): id of asset_model + num = INT(10) + extension = VARCHAR(4) + +roles - + id = INT(10) + name = VARCHAR(255): 1='Disabled', 2='Viewer', 4='User', 8='Contributor', 16='Administrator' + +transaction_types - + id = INT(10) + name = VARCHAR(255): 1='Check-out', 2='Check-in', 3='Restrict', 4='Unrestrict' + +transactions - + id = INT(10) + type = INT(10): id of transaction_type + user = INT(10): id of user + asset = INT(10): id of asset + time = DATETIME + location = INT(10): id of location + purpose = VARCHAR(255) + finish = DATE + notes = VARCHAR(255) + +asset_model_relations - Join table of asset_models & relations + id = INT(10) + source = INT(10): id of asset_model + relation = INT(10): id of relation + target = INT(10): id of asset_model + + diff --git a/instances/myinstance/data.sql b/instances/myinstance/data.sql index 6d7a9ae..bfee125 100755 --- a/instances/myinstance/data.sql +++ b/instances/myinstance/data.sql @@ -91,4 +91,4 @@ INSERT INTO `myinstance_asset_model_categories` (`id`, `model`, `category`) VALU -- config-todo: add admin account INSERT INTO `myinstance_users` (`id`, `uid`, `name`, `email`, `role`) VALUES -(1, 111111111, 'admin', 'admin@isle.local', 16); \ No newline at end of file +(1, 1, 'admin', 'admin@isle.local', 16); diff --git a/instances/myinstance2/data.sql b/instances/myinstance2/data.sql index 7ac59af..a979ba2 100644 --- a/instances/myinstance2/data.sql +++ b/instances/myinstance2/data.sql @@ -91,4 +91,4 @@ INSERT INTO `myinstance2_asset_model_categories` (`id`, `model`, `category`) VAL -- config-todo: add admin account INSERT INTO `myinstance2_users` (`id`, `uid`, `name`, `email`, `role`) VALUES -(1, 111111111, 'admin', 'admin@isle.local', 16); \ No newline at end of file +(1, 1, 'admin', 'admin@isle.local', 16); diff --git a/isle-init.py b/isle-init.py new file mode 100755 index 0000000..fe03cd9 --- /dev/null +++ b/isle-init.py @@ -0,0 +1,418 @@ +#!/usr/bin/env python +#*************************************************************************** +#* Copyright 2017 Pete DiMarco +#* +#* Licensed under the Apache License, Version 2.0 (the "License"); +#* you may not use this file except in compliance with the License. +#* You may obtain a copy of the License at +#* +#* http://www.apache.org/licenses/LICENSE-2.0 +#* +#* Unless required by applicable law or agreed to in writing, software +#* distributed under the License is distributed on an "AS IS" BASIS, +#* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +#* See the License for the specific language governing permissions and +#* limitations under the License. +#*************************************************************************** +# +# Name: isle-init.py +# Version: 0.1 +# Date: 2017-10-19 +# Written by: Pete DiMarco +# Based on: isle-init.sh +# +# Description: +# Initialization script for ISLE's MySQL database. +# +# Limitations: +# - Assumes Python 2.7 or possibly lower. +# - Assumes Posix-compatible shell. +# - Requires Linux-like OS. +# - Assumes PHP can be run from the shell to access the Secrets.php file. +# - Must be run by user root. + +import os +import sys +import re +import subprocess +import MySQLdb +import getpass +import argparse +import sqlparse +import platform +import enum +import shutil + + +BASE_DIR = '/var/www/' +SECRETS_FILE = BASE_DIR + 'webroot/isle/includes/classes/Secrets.php' +PHP_BASE_CMD = 'php -r "@include \'' + SECRETS_FILE + "';" +LOGROTATE_FILE_PAT = "/etc/logrotate.d/isle-%s" +INSTANCE_DIR_PAT = BASE_DIR + "instances/%s/" +INSTANCE_NAMES = [ 'myinstance', 'myinstance2' ] +SQL_FILES = [ 'init.sql', 'data.sql' ] +APACHE_CONF_FILE = 'isle.local.conf' +APACHE_INST_CONF_PAT = 'isle.local.%s.conf' + +EPILOG = "" +DEBUG = False + + +# \class OSType +# \public +# \brief Figures out what type of Linux we're running on. +class OSType(): + REDHAT = 0 + DEBIAN = 1 + REDHAT_LIKE = ["redhat", "suse", "scientific linux", "centos", "fedora"] + DEBIAN_LIKE = ["debian", "ubuntu", "kubuntu", "mint"] + REDHAT_RESTART = "systemctl restart httpd.service" + DEBIAN_RESTART = "service apache2 reload" + REDHAT_APACHE_DIR = '/etc/httpd/' + DEBIAN_APACHE_DIR = '/etc/apache2/sites-available/' + DEBIAN_SITE_INST_PAT= 'isle.local.%s' + + # \fn __init__ + # \public + # \brief Constructor: Classifies OS as DEBIAN or REDHAT. + # \param [in] redhat boolean + # \param [in] debian boolean + # \return OSType object + def __init__(self, redhat = False, debian = False): + global DEBUG + if redhat and debian: + print('ERROR: RedHat and Debian are mutually exclusive.') + exit(0) + elif redhat: # Forcing RedHat. + self.os_type = OSType.REDHAT + return + elif debian: # Forcing Debian. + self.os_type = OSType.DEBIAN + return + + if os.name == "nt" or platform.system() == "Windows": + print("This program is intended for use on Linux or similar Posix OSes.") + elif platform.system() == "Linux": + distro = platform.linux_distribution()[0].lower() # Get the distro name. + if DEBUG: + print("Linux distro = %s." % distro) + if distro in OSType.REDHAT_LIKE: + self.os_type = OSType.REDHAT + return + elif distro in OSType.DEBIAN_LIKE: + self.os_type = OSType.DEBIAN + return + else: + print("Unrecognized Linux distribution (%s)" % distro) + else: + print("Unrecognized OS (%s)" % platform.system()) + + print("To force the use of Debian or RedHat features, use --debian or --redhat.") + exit(0) + + # \fn restart_server + # \public + # \brief Restarts the web server. + # \return + def restart_server(self): + global DEBUG + if self.os_type == OSType.REDHAT: + OSType.run_cmd(OSType.REDHAT_RESTART) + elif self.os_type == OSType.DEBIAN: + OSType.run_cmd(OSType.DEBIAN_RESTART) + + # \fn install_conf + # \public + # \brief Installs the Apache configuration files on the server. + # \return + def install_conf(self): + global DEBUG + if self.os_type == REDHAT: + print('NOTE: You must manually edit %sconf/httpd.conf' % + OSType.REDHAT_APACHE_DIR) + shutil.copy(BASE_DIR + APACHE_CONF_FILE, + OSType.REDHAT_APACHE_DIR + 'conf.d/' + APACHE_CONF_FILE) + # Copy Apache config for each instance: + for inst in INSTANCE_NAMES: + inst_dir = INSTANCE_DIR_PAT % inst + inst_conf_file = APACHE_INST_CONF_PAT % inst + shutil.copy(inst_dir + inst_conf_file, + OSType.REDHAT_APACHE_DIR + 'conf.d/' + inst_conf_file) + if DEBUG: + print('Copied ' + inst_dir + inst_conf_file) + + elif self.os_type == DEBIAN: + shutil.copy(BASE_DIR + APACHE_CONF_FILE, + OSType.DEBIAN_APACHE_DIR + APACHE_CONF_FILE) + # Copy Apache config for each instance: + for inst in INSTANCE_NAMES: + inst_dir = INSTANCE_DIR_PAT % inst + inst_conf_file = APACHE_INST_CONF_PAT % inst + shutil.copy(inst_dir + inst_conf_file, + OSType.DEBIAN_APACHE_DIR + APACHE_CONF_FILE) + OSType.run_cmd('a2ensite ' + (OSType.DEBIAN_SITE_INST_PAT % inst)) + if DEBUG: + print('Copied ' + inst_dir + inst_conf_file) + + # \fn run_cmd + # \public + # \brief Runs the command in a shell. Returns an empty string if + # an exception is raised. + # \param [in] cmd_str string + # \param [in] ignore_exit_1 boolean + # \return string + @staticmethod + def run_cmd(cmd_str, ignore_exit_1 = False): + global DEBUG + result = "" + try: + # If we have a reasonable version of Python: + if sys.version_info >= (2,7): + result = subprocess.check_output(cmd_str, shell=True) + else: # Else this machine needs an upgrade: + fp = os.popen(cmd_str, "r") + result = fp.read() + fp.close() + except Exception as e: + # grep will return errno == 1 if it doesn't match any lines + # in its input stream. We want to ignore this case since it's + # not really an error. + if (type(e) != subprocess.CalledProcessError or e.returncode != 1 or + not ignore_exit_1): + print("\tThis command:") + print(cmd_str) + print("\tGenerated this exception:") + print(e, str(e)) + exit(0) + return result + + +# \fn read_file +# \public +# \brief Reads the contents of a file into 1 large string. +# \param [in] file_name string +# \return string +def read_file(file_name): + result = "" + if os.path.exists(file_name) and os.path.isfile(file_name): + try: + fp = open(file_name, "r") + result = fp.read() + fp.close() + except: + print("ERROR: Problem reading %s." % file_name) + exit(0) + else: + print("ERROR: %s does not exist." % file_name) + exit(0) + return result.decode("utf-8-sig").encode("utf-8") # Handle BOM. + + +# \fn ask +# \public +# \brief Prompts the user for a yes or no answer. +# \param [in] question string +# \return boolean +def ask(question): + while True: + answer = raw_input(question + " ").lower() + if len(answer) == 0 or answer[0] == "y": + return True + elif answer[0] == "n": + return False + else: + print('Please enter "yes" or "no".') + print('Just pressing is assumed to mean "yes".') + + +# \fn send_cmd +# \public +# \brief Sends a command to a MySQL server. +# \param [in] cursor cursor object +# \param [in] cmd string +# \return None +def send_cmd(cursor, cmd): + global DEBUG + if not cmd: + print("Skipping empty %s" % type(cmd)) + return + +# try: + cursor.execute(cmd) + retval = cursor.fetchall() + if DEBUG: + print("%s returned: %s" % (cmd, retval if retval else 'N/A')) +# except Exception as e: +# print("\tThis command:") +# print(cmd) +# print("\tGenerated this exception:") +# print(e, str(e)) + + +# \fn copy_dir +# \public +# \brief Copies a directory because shutil.copytree() is broken. +# \param [in] src string +# \param [in] dest string +# \param [in] ignore set? +# \param [in] interactive bool +# \return None +def copy_dir(src, dest, ignore, interactive): + global DEBUG + try: + if os.path.exists(dest): # If dest already exists: + if os.path.isfile(dest): # And dest is a file: + if ask("Delete the file %s first?" % dest): + os.remove(dest) # Remove the file. + else: + print("ERROR: The file %s is in the way. Please move it first." % + dest) + exit(0) + elif os.path.isdir(dest): # Else dest is a directory: + if os.listdir(dest): # Check if dest is empty. + print("WARNING: %s exists and is not empty." % dest) + if ask("Delete the existing directory %s first?" % dest): + shutil.rmtree(dest) # Delete the directory. + else: + print("ERROR: The directory %s is in the way. Please move it first." % + dest) + exit(0) + else: # Else dest is unknow FS object: + print("ERROR: %s exists but is of unknown type.") + exit(0) + + # Now dest does not exist: + if not interactive or ask("Copy ISLE's files from %s to %s?" % + (src, dest)): + # copytree() won't copy to a directory that already exists. + shutil.copytree(src, dest, ignore = ignore) + + except Exception as e: + print(e, str(e)) + exit(0) + + + +if __name__ == "__main__": + cwd = os.getcwd() + # Parse command line arguments: + parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, + description="ISLE installation script.", + epilog=EPILOG) + parser.add_argument('-i', '--interactive', action='store_true', default=False, + help='Interactive mode.') + parser.add_argument('-r', '--redhat', action='store_true', default=False, + help='Use RedHat-style "systemctl" commands.') + parser.add_argument('-d', '--debian', action='store_true', default=False, + help='Use Debian-style "service" commands.') + parser.add_argument('-c', '--clean', action='store_true', default=False, + help='Drop the existing database and start clean.') + parser.add_argument('--copy', action='store_true', default=False, + help='Copy ISLE files from %s to %s.' % (cwd, BASE_DIR)) + parser.add_argument('-D', '--DEBUG', action='store_true', default=False, + help='Enable debugging mode.') + args = parser.parse_args() + DEBUG = args.DEBUG + + # Check the effective user name: + if getpass.getuser() != "root": + print("Please run this script as root.") + exit(0) + + my_os = OSType(debian = args.debian, redhat = args.redhat) + + if args.copy: + copy_dir(cwd, BASE_DIR, + shutil.ignore_patterns('.git*', '.vagrant', 'Vagrantfile'), + args.interactive) + if DEBUG: + print("Copied files and directories from %s to %s" % (cwd, BASE_DIR)) + + if not os.path.exists(SECRETS_FILE) or not os.path.isfile(SECRETS_FILE): + print("ERROR: Cannot find %s." % SECRETS_FILE) + template = SECRETS_FILE + '.template' + if not os.path.exists(template) or not os.path.isfile(template): + print(" Cannot find %s either." % template) + elif ask("Shall I initialize %s with the template file?" % SECRETS_FILE): + shutil.copy(template, SECRETS_FILE) + print("Please add security information to %s, then rerun this program." % + SECRETS_FILE) + print("DO NOT ADD %s TO YOUR SCM!" % SECRETS_FILE) + exit(0) + + mysql_user = OSType.run_cmd(PHP_BASE_CMD + + 'echo ISLE\Secrets::DB_USER;"').strip() + mysql_pwd = OSType.run_cmd(PHP_BASE_CMD + + 'echo ISLE\Secrets::DB_PASSWORD;"').strip() + mysql_host = OSType.run_cmd(PHP_BASE_CMD + + 'echo ISLE\Secrets::DB_HOST_NAME;"').strip() + mysql_port = OSType.run_cmd(PHP_BASE_CMD + + 'echo ISLE\Secrets::DB_PORT;"').strip() + mysql_db_name = OSType.run_cmd(PHP_BASE_CMD + + 'echo ISLE\Secrets::DB_NAME;"').strip() + + # Connecting to MySQL's management DB in order to create the ISLE DB: + db = MySQLdb.connect(host = mysql_host, user = mysql_user, + use_unicode = True, charset = "utf8", + passwd = mysql_pwd, db = "mysql" ) + cur = db.cursor() + if DEBUG: + print("Connected to MySQL.") + + send_cmd(cur, "SET NAMES 'utf8';") # Turn on Unicode UTF8. + + if args.clean and ask("Are you sure you want to drop the existing ISLE database?"): + print("Dropping existing database '%s'." % mysql_db_name) + send_cmd(cur, "DROP DATABASE %s;" % mysql_db_name) + + if not args.interactive or ask("Create ISLE's database?"): + try: + send_cmd(cur, "CREATE DATABASE %s;" % mysql_db_name) + except Exception as e: + if type(e) is MySQLdb.ProgrammingError and e[0] == 1007: + print("Database %s already exists." % mysql_db_name) + + db.close() # Done with MySQL's management DB. + + if not args.interactive or ask("Populate all database instances?"): + # Connecting to the new ISLE DB: + isle_db = MySQLdb.connect(host = mysql_host, user = mysql_user, + use_unicode = True, charset = "utf8", + passwd = mysql_pwd, db = mysql_db_name) + isle_cur = isle_db.cursor() + send_cmd(isle_cur, "SET NAMES 'utf8';") # Turn on Unicode UTF8. + + # Initialize DB tables and data for each instance: + for inst in INSTANCE_NAMES: + inst_dir = INSTANCE_DIR_PAT % inst + # For each type of SQL file: + for f in SQL_FILES: + cmds = sqlparse.split(read_file(inst_dir + f)) + for cmd in cmds: + send_cmd(isle_cur, cmd) + + isle_db.close() + + if not args.interactive or ask("Install Apache configuration files?"): + my_os.install_conf() + + if not args.interactive or ask("Modify logrotate files?"): + # Create logrotate configuration for each instance: + for inst in INSTANCE_NAMES: + with open(LOGROTATE_FILE_PAT % inst, "a") as f: + f.write(""" +/var/www/instances/%s/logs/*.log { + yearly + maxsize 2M + rotate 5 + notifempty + missingok + } +""" % inst) + + # Restart Apache for configuration changes to take effect: + if not args.interactive or ask("Restart the webserver?"): + my_os.restart_server() + elif DEBUG: + print("Did not restart webserver.") + diff --git a/isle-rest-api.txt b/isle-rest-api.txt new file mode 100644 index 0000000..a670089 --- /dev/null +++ b/isle-rest-api.txt @@ -0,0 +1,25 @@ + +ISLE REST API: + method=logout + method=feedback&type=bug&steps=S # length of S <= 2000 + method=feedback&type=feature&description=D[&attachment=?] + method=feedback&type=chore&description=D[&attachment=?] + method=add&model=User[&chkEmail=EMAIL] + method=add: + method=update: + method=delete: + model=Version + model=User + model=MODEL_NAME + model=TransactionCheckout + model=TransactionCheckin + model=TransactionRestrict + model=TransactionUnrestrict + method=getAll: + model=Version[&filter=?] + model=Asset[&filter=?][&tree=TF] + model=Transaction[&filter=?][&tree=TF] + method=getForeignKeyReferences&nodeId=ID + +$_REQUEST contains $_POST + diff --git a/webroot/isle/assetmodels.php b/webroot/isle/assetmodels.php index c94126c..dca975c 100755 --- a/webroot/isle/assetmodels.php +++ b/webroot/isle/assetmodels.php @@ -13,7 +13,8 @@ if($action != 'new' && $action != 'edit') { // redirect to 404 page if no action exists. - throw new ISLE\Exception('The requested assetmodel action is invalid.', ISLE\Exception::FOUROFOUR); + throw new ISLE\Exception('The requested assetmodel action is invalid.', + ISLE\Exception::FOUROFOUR); } if($u['role'] <= ISLE\Models\Role::USER) { @@ -23,7 +24,8 @@ exit(); } - //setup an array or structure that contains the field names. so you only have one place to update if you want to change them + // Setup an array or structure that contains the field names, so you only + // have one place to update if you want to change them. $fieldNames['assetModelForm']['id'] = "hidId"; $fieldNames['assetModelForm']['desc'] = "txtDesc"; $fieldNames['assetModelForm']['model'] = "txtModel"; @@ -118,8 +120,10 @@ if(!isset($_POST['deleteBtn'])) { // Validate file type - if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_OK && $_FILES[$othFieldNames['attachment']]["tmp_name"] != "") { - $newfilename = preg_replace('/\.pdf$/', '', $_FILES[$othFieldNames['attachment']]["name"]); + if ($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_OK and + $_FILES[$othFieldNames['attachment']]["tmp_name"] != "") { + $newfilename = preg_replace('/\.pdf$/', '', + $_FILES[$othFieldNames['attachment']]["name"]); $newfilename = preg_replace('/\W/', '', $newfilename); $userfile_tmp = $_FILES[$othFieldNames['attachment']]["tmp_name"]; $finfo = finfo_open(FILEINFO_MIME_TYPE); @@ -131,17 +135,19 @@ break; default: //wrong file type. - $valErrors['attachment'] = 'Attachment must be apdf.'; + $valErrors['attachment'] = 'Attachment must be a PDF.'; throw new ISLE\UIException('One or more errors occurred', $valErrors); } - if(! (intval($_POST[$othFieldNames['attachmentNum']]) >= 0) || $newfilename == '') { + if(! (intval($_POST[$othFieldNames['attachmentNum']]) >= 0) or + $newfilename == '') { throw new ISLE\Exception('There was a problem with the attachmentNum or newfilename vars.', ISLE\Exception::UPLOAD); } } // Validate file size. - if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_INI_SIZE || $_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_FORM_SIZE) { + if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_INI_SIZE or + $_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_FORM_SIZE) { $uploadMax = ini_get('upload_max_filesize'); $postMax = ini_get('post_max_size'); $maxSize = $uploadMax - $postMax > 0 ? $postMax : $uploadMax; @@ -150,7 +156,8 @@ } // Catch other file upload errors. - if($_FILES[$othFieldNames['attachment']]["error"] > 0 && $_FILES[$othFieldNames['attachment']]["error"] != UPLOAD_ERR_NO_FILE) { + if($_FILES[$othFieldNames['attachment']]["error"] > 0 and + $_FILES[$othFieldNames['attachment']]["error"] != UPLOAD_ERR_NO_FILE) { throw new ISLE\Exception('An unknown error occurred while trying to upload an asset attachment file.', ISLE\Exception::UPLOAD); } @@ -159,7 +166,8 @@ if(!isset($_POST[$othFieldNames['removeImage']])) { // Validate file type. - if($_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_OK && $_FILES[$othFieldNames['image']]["tmp_name"] != "") { + if($_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_OK and + $_FILES[$othFieldNames['image']]["tmp_name"] != "") { $userfile_tmp = $_FILES[$othFieldNames['image']]["tmp_name"]; $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $userfile_tmp); @@ -182,7 +190,8 @@ } // Validate file size. - if($_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_INI_SIZE || $_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_FORM_SIZE) { + if($_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_INI_SIZE or + $_FILES[$othFieldNames['image']]["error"] == UPLOAD_ERR_FORM_SIZE) { $uploadMax = ini_get('upload_max_filesize'); $postMax = ini_get('post_max_size'); $maxSize = $uploadMax - $postMax > 0 ? $postMax : $uploadMax; @@ -191,7 +200,8 @@ } // Catch other file upload errors. - if($_FILES[$othFieldNames['image']]["error"] > 0 && $_FILES[$othFieldNames['image']]["error"] != UPLOAD_ERR_NO_FILE) { + if($_FILES[$othFieldNames['image']]["error"] > 0 and + $_FILES[$othFieldNames['image']]["error"] != UPLOAD_ERR_NO_FILE) { throw new ISLE\Exception('An unknown error occurred while trying to upload an asset model image.', ISLE\Exception::UPLOAD); } } @@ -199,8 +209,8 @@ if(isset($_POST['updateBtn'])) { $_SESSION['addedModel'] = $class->id; - //delete any attachments marked with 'delete'. - //the highest num for this model is sent in a hidden field. + // Delete any attachments marked with 'delete'. + // The highest num for this model is sent in a hidden field. foreach($_POST[$othFieldNames['removeAtt']] as $removeAtt) { $pat = '/^' . $_SESSION['addedModel'] . '_[1-9][0-9]*\.pdf$/'; if(preg_match($pat, $removeAtt)) { @@ -212,7 +222,8 @@ $attNum = $tmp[1]; if(!unlink($attachment_location . '/' . $removeAtt)) { - throw new ISLE\Exception('Could not delete assetmodel attachment.', ISLE\Exception::UPLOAD); + throw new ISLE\Exception('Could not delete assetmodel attachment.', + ISLE\Exception::UPLOAD); } $class5 = new ISLE\Models\AssetModelAttachment(); @@ -231,7 +242,8 @@ $addedModel = $svc->$svcMethod($class); - //store the newly added/saved model id in session so it can be used on the new asset form. + // Store the newly added/saved model id in session so it can be used + // on the new asset form. if(isset($_POST['updateBtn']) || isset($_POST['deleteBtn'])) { $_SESSION['addedModel'] = $class->id; } @@ -412,9 +424,12 @@ else { // Process Uploaded File if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_OK && $_FILES[$othFieldNames['attachment']]["tmp_name"] != "") { - //change name of file. only accept pdf. check contents for mime. disable direct access and use a proxy script to provide access. make sure files do not have execute permission. + // Change name of file. Only accept pdf. Check contents for mime. + // Disable direct access and use a proxy script to provide access. + // Make sure files do not have execute permission. - //the highest num for this model is sent in a hidden field. add 1 to this and use for filename. model_num.pdf + // The highest num for this model is sent in a hidden field. Add 1 + // to this and use for filename. model_num.pdf $attachmentNum = intval($_POST[$othFieldNames['attachmentNum']]) + 1; $attachment_location .= '/' . $_SESSION['addedModel'] . '_' . $attachmentNum . $fileExt; if(!move_uploaded_file($userfile_tmp, $attachment_location)) { @@ -454,7 +469,8 @@ } if(isset($_POST['deleteBtn']) && isset($_POST['fromJS'])) { - exit('while(1);{"result":{"status":"success", "value":"Asset model deleted successfully."}}'); + //exit('while(1);{"result":{"status":"success", "value":"Asset model deleted successfully."}}'); + exit('{"result":{"status":"success", "value":"Asset model deleted successfully."}}'); } exit(); } @@ -519,8 +535,14 @@ $attachments = $svc->getAll($attachmentsClass, null, null, null, null, $filter, $order); if(!empty($_POST[$fieldNames['assetModelForm']['img']])) { - $modelImg['source'] = $rootdir . 'uploads/images/assetmodels/thumbs/' . $itemToEdit . '.' . $_POST[$fieldNames['assetModelForm']['img']] . '?ts=' . strtotime($modelDetails->img_modified); - $modelImg['target'] = $rootdir . 'uploads/images/assetmodels/' . $itemToEdit . '.' . $_POST[$fieldNames['assetModelForm']['img']] . '?ts=' . strtotime($modelDetails->img_modified); + $modelImg['source'] = $rootdir . 'uploads/images/assetmodels/thumbs/' . + $itemToEdit . '.' . + $_POST[$fieldNames['assetModelForm']['img']] . + '?ts=' . strtotime($modelDetails->img_modified); + $modelImg['target'] = $rootdir . 'uploads/images/assetmodels/' . + $itemToEdit . '.' . + $_POST[$fieldNames['assetModelForm']['img']] . + '?ts=' . strtotime($modelDetails->img_modified); } } @@ -549,20 +571,25 @@ $models = $svc->getAll($modelClass, null, null, null, null, null, $order); } - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Asset Models"; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Asset Models"; switch($action) { case 'new': - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Add Asset Model"; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Add Asset Model"; break; case 'edit': - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Edit Asset Model " . $itemToEdit . ""; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Edit Asset Model " . $itemToEdit . ""; break; } $tmpl_headcontent .= $tmpl_headcontent_main; - $tmpl_headcontent .= ''; - $tmpl_headcontent .= ''; + $tmpl_headcontent .= ''; + $tmpl_headcontent .= ''; $tmpl_javascripts = $tmpl_javascripts_main; diff --git a/webroot/isle/assets.php b/webroot/isle/assets.php index 749908a..5007287 100755 --- a/webroot/isle/assets.php +++ b/webroot/isle/assets.php @@ -1,52 +1,56 @@ = 0) || $newfilename == '') { + if(! (intval($_POST[$othFieldNames['attachmentNum']]) >= 0) || + $newfilename == '') { throw new ISLE\Exception('There was a problem with the attachmentNum or newfilename vars.', ISLE\Exception::UPLOAD); } } // Validate file size. - if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_INI_SIZE || $_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_FORM_SIZE) { + if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_INI_SIZE || + $_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_FORM_SIZE) { $uploadMax = ini_get('upload_max_filesize'); $postMax = ini_get('post_max_size'); $maxSize = $uploadMax - $postMax > 0 ? $postMax : $uploadMax; @@ -180,7 +192,8 @@ } // Catch other file upload errors. - if($_FILES[$othFieldNames['attachment']]["error"] > 0 && $_FILES[$othFieldNames['attachment']]["error"] != UPLOAD_ERR_NO_FILE) { + if($_FILES[$othFieldNames['attachment']]["error"] > 0 && + $_FILES[$othFieldNames['attachment']]["error"] != UPLOAD_ERR_NO_FILE) { throw new ISLE\Exception('An unknown error occurred while trying to upload an asset attachment file.', ISLE\Exception::UPLOAD); } @@ -200,7 +213,8 @@ $attNum = $tmp[1]; if(!unlink($attachment_location . '/' . $removeAtt)) { - throw new ISLE\Exception('Could delete asset attachment.', ISLE\Exception::UPLOAD); + throw new ISLE\Exception('Could delete asset attachment.', + ISLE\Exception::UPLOAD); } $class5 = new ISLE\Models\AssetAttachment(); @@ -241,7 +255,8 @@ if ($entry != "." && $entry != "..") { if(preg_match($pat, $entry)) { if(!unlink($attachment_location . '/' . $entry)) { - throw new ISLE\Exception('Could delete asset attachment.', ISLE\Exception::UPLOAD); + throw new ISLE\Exception('Could delete asset attachment.', + ISLE\Exception::UPLOAD); } } } @@ -251,10 +266,14 @@ } else { // Process Uploaded File - if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_OK && $_FILES[$othFieldNames['attachment']]["tmp_name"] != "") { - //change name of file. only accept pdf. check contents for mime. disable direct access and use a proxy script to provide access. make sure files do not have execute permission. + if($_FILES[$othFieldNames['attachment']]["error"] == UPLOAD_ERR_OK && + $_FILES[$othFieldNames['attachment']]["tmp_name"] != "") { + //change name of file. only accept pdf. check contents for mime. + //disable direct access and use a proxy script to provide access. + //make sure files do not have execute permission. - //the highest num for this asset is sent in a hidden field. add 1 to this and use for filename. asset_num.pdf + //the highest num for this asset is sent in a hidden field. + //add 1 to this and use for filename. asset_num.pdf $attachmentNum = intval($_POST[$othFieldNames['attachmentNum']]) + 1; $attachment_location .= '/' . $addedAsset . '_' . $attachmentNum . $fileExt; if(!move_uploaded_file($userfile_tmp, $attachment_location)) { @@ -290,7 +309,8 @@ } if(isset($_POST['deleteBtn']) && isset($_POST['fromJS'])) { - exit('while(1);{"result":{"status":"success", "value":"Asset deleted successfully."}}'); + //exit('while(1);{"result":{"status":"success", "value":"Asset deleted successfully."}}'); + exit('{"result":{"status":"success", "value":"Asset deleted successfully."}}'); } exit(); @@ -397,7 +417,8 @@ $filter['cols'][0]['val'] = $itemToEdit; $order[0]['col'] = 'num'; //get list of attachments from db, so ui can load into dropdown. - $attachments = $svc->getAll($attachmentsClass, null, null, null, null, $filter, $order); + $attachments = $svc->getAll($attachmentsClass, null, null, null, null, + $filter, $order); } if($action == '') { @@ -414,24 +435,32 @@ } } - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Assets"; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Assets"; switch($action) { case 'new': - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Add Asset"; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Add Asset"; break; case 'edit': - $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . " - Edit Asset " . $itemToEdit . ""; + $tmpl_headcontent = "ISLE: " . ISLE\Service::getInstanceName() . + " - Edit Asset " . $itemToEdit . ""; break; } $tmpl_headcontent .= $tmpl_headcontent_main; if ($action == '') { - $tmpl_headcontent .= ''; - $tmpl_headcontent .= ''; + $tmpl_headcontent .= ''; + $tmpl_headcontent .= ''; } else { - $tmpl_headcontent .= ''; + $tmpl_headcontent .= ''; } $tmpl_javascripts = $tmpl_javascripts_main; @@ -449,7 +478,8 @@ if(!isset($_POST['fromJS'])) { if(isset($_SESSION['querystring'])){ - echo ''; + echo ''; } else { echo ''; diff --git a/webroot/isle/cdn/scripts-dev/src/app/NodeManager.js b/webroot/isle/cdn/scripts-dev/src/app/NodeManager.js index 1ac5dbf..2135e03 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/NodeManager.js +++ b/webroot/isle/cdn/scripts-dev/src/app/NodeManager.js @@ -2,7 +2,7 @@ define(["jquery", "./Util"], function($, Util) { var NodeManager = function() { - this.intialize = function(options) { + this.initialize = function(options) { var that = this; that.props = {}; @@ -313,7 +313,7 @@ define(["jquery", "./Util"], function($, Util) { //an error occurred on the server. $('#userMessage').remove(); $('#' + that.props.options.tableId).html(''); - $('').hide().prependTo('.listRight').fadeIn(150); + $('').hide().prependTo('.listRight').fadeIn(150); $('.scroll-pane').addClass('has-message'); that.props.retVal = ''; $('#addBtn').removeAttr("disabled"); @@ -337,7 +337,7 @@ define(["jquery", "./Util"], function($, Util) { //todo: refactor into a separate method. $('#userMessage').remove(); //todo: make this work for asset details page. - $('').hide().prependTo('.listRight').fadeIn(150); + $('').hide().prependTo('.listRight').fadeIn(150); $('.scroll-pane').addClass('has-message'); throw err; } @@ -645,11 +645,15 @@ define(["jquery", "./Util"], function($, Util) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - //remove loading text and show and error in its place. + //remove loading text and show an error in its place. // enable the buttons $("#" + that.props.options.dialogId + whichModal + " .modal-footer button").removeAttr("disabled"); //replace loading text with error text. - $("#" + that.props.options.dialogId + whichModal + " .modal-footer .footerRight").addClass('errorText').html('I\'m sorry. Something went wrong.'); + $("#" + that.props.options.dialogId + whichModal + + " .modal-footer .footerRight") + .addClass('errorText') + .html('I\'m sorry. Something went wrong (NodeManager.js:655 ' + + errorThrown + ').'); var retVal2 = ''; return false; @@ -693,7 +697,7 @@ define(["jquery", "./Util"], function($, Util) { var fi, formField, msgElement; // Integrity Constraint violation if(retVal2 == 'duplicate') { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (duplicate)."); } // UI Exception else { @@ -765,7 +769,7 @@ define(["jquery", "./Util"], function($, Util) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (NodeManager.js:772 " + errorThrown + ")."); return false; }, success: function(data, textStatus, jqXHR) { @@ -847,13 +851,16 @@ define(["jquery", "./Util"], function($, Util) { dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { if(saveMethod == 'delete') { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (saveMethod == delete)."); } else { // enable the buttons $("#" + that.props.options.dialogId + " .modal-footer button").removeAttr("disabled"); //replace loading text with error text. - $("#" + that.props.options.dialogId + " .modal-footer .footerRight").addClass('errorText').html('I\'m sorry. Something went wrong.'); + $("#" + that.props.options.dialogId + " .modal-footer .footerRight") + .addClass('errorText') + .html('I\'m sorry. Something went wrong (NodeManager.js:862 ' + + errorThrown + ').'); } var retVal2 = ''; return false; @@ -961,7 +968,8 @@ define(["jquery", "./Util"], function($, Util) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (NodeManager.js:971 " + + errorThrown + ")."); return false; }, success: function(data, textStatus, jqXHR) { @@ -998,7 +1006,8 @@ define(["jquery", "./Util"], function($, Util) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (NodeManager.js:1009 " + + errorThrown + ")."); }, success: options.successFunction }); @@ -1093,4 +1102,4 @@ define(["jquery", "./Util"], function($, Util) { } return NodeManager; -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/assetForm.js b/webroot/isle/cdn/scripts-dev/src/app/views/assetForm.js index 7d81a6b..b344aec 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/assetForm.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/assetForm.js @@ -49,7 +49,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - $('#modelDetails').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#modelDetails').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -77,7 +77,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - $('#modelDetails').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#modelDetails').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -110,7 +110,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - $('#modelDetails').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#modelDetails').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -139,7 +139,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - $('#modelDetails').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#modelDetails').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -194,7 +194,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - $('#modelDetails').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#modelDetails').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -369,7 +369,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgr.intialize(options); + NodeMgr.initialize(options); $( "#" + options.fieldNames[0].finish ).datepicker({ showOn: "button", @@ -406,7 +406,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgrLocation.intialize(optionsLocation); + NodeMgrLocation.initialize(optionsLocation); var opts = { fieldNames: optionsLocation.fieldNames, @@ -442,4 +442,4 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { $('#' + optionsLocation.fieldNames['room']).autocomplete(NodeMgrLocation.buildACOptions(opts3)); } }); -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/assetmodels.js b/webroot/isle/cdn/scripts-dev/src/app/views/assetmodels.js index ab94950..4288c14 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/assetmodels.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/assetmodels.js @@ -117,7 +117,8 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { $('.tagit .ui-autocomplete-input').val('Load failed.'); - $('#msg-' + opts.fieldNames['categories']).html("I'm sorry. Something went wrong."); + $('#msg-' + opts.fieldNames['categories']) + .html("I'm sorry. Something went wrong (" + errorThrown + ")."); return false; }, success: function(data, textStatus, jqXHR) { @@ -209,7 +210,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }; - NodeMgr.intialize(options); + NodeMgr.initialize(options); $( "#" + options.fieldNames['attribute'] ).combobox({ selected: function(event, ui) { @@ -291,7 +292,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }; - NodeMgr2.intialize(roptions); + NodeMgr2.initialize(roptions); if($('html').attr('data-role') >= ISLE_CONTRIBUTOR) { @@ -313,7 +314,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgrMfr.intialize(optionsMfr); + NodeMgrMfr.initialize(optionsMfr); var NodeMgrRelation = new NodeManager(); @@ -333,7 +334,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgrRelation.intialize(optionsRelation); + NodeMgrRelation.initialize(optionsRelation); //todo: replace these handlers with a common reusable function. $('#' + optionsRelation.dialogId).on('shown', function() { @@ -349,4 +350,4 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }); -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/assets.js b/webroot/isle/cdn/scripts-dev/src/app/views/assets.js index 2532d6b..155bd72 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/assets.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/assets.js @@ -204,7 +204,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }); - NodeMgr.intialize(options); + NodeMgr.initialize(options); $('#showAll, #VerColMenu span.selector').on('click keypress', function(e){ if(e.type == 'click' || (e.type == 'keypress' && e.which == 13)) { @@ -449,7 +449,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgrLocation.intialize(optionsLocation); + NodeMgrLocation.initialize(optionsLocation); $('#' + optionsLocation.dialogId).on('shown', function() { //increase the z-index of the modal and its backdrop +20 diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/attributes.js b/webroot/isle/cdn/scripts-dev/src/app/views/attributes.js index 39b77eb..064ca7e 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/attributes.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/attributes.js @@ -55,6 +55,6 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); }); }); \ No newline at end of file diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/attributetypes.js b/webroot/isle/cdn/scripts-dev/src/app/views/attributetypes.js index 208104e..a3fa89e 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/attributetypes.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/attributetypes.js @@ -121,7 +121,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); $( "#" + options.fieldNames['parent'] ).combobox(); }); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/categories.js b/webroot/isle/cdn/scripts-dev/src/app/views/categories.js index 2e8e020..426a9bf 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/categories.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/categories.js @@ -103,7 +103,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); $( "#" + options.fieldNames['parent'] ).combobox(); }); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/locations.js b/webroot/isle/cdn/scripts-dev/src/app/views/locations.js index 161a4ec..0487fce 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/locations.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/locations.js @@ -64,7 +64,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); var opts = { fieldNames: options.fieldNames, diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/manufacturers.js b/webroot/isle/cdn/scripts-dev/src/app/views/manufacturers.js index 02d74ab..cdefef8 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/manufacturers.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/manufacturers.js @@ -21,15 +21,19 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { $.each(retVal['items'], function(index, val){ editTableCol = ''; if($('html').attr('data-role') >= ISLE_CONTRIBUTOR) { - editTableCol = ''; + editTableCol = ''; } tableHTML += '' + editTableCol; - tableHTML += '' + Util.htmlEncode(Util.abbreviate(val['name'], 100)) + ''; + tableHTML += '' + + Util.htmlEncode(Util.abbreviate(val['name'], 100)) + ''; if(val['url'] !== null && val['url'].length > 0) { - tableHTML += ' '; + tableHTML += ' '; } else { tableHTML += ''; @@ -54,6 +58,6 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); }); -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/relations.js b/webroot/isle/cdn/scripts-dev/src/app/views/relations.js index a243abd..9e58358 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/relations.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/relations.js @@ -40,6 +40,6 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { rowsClickable: rowsClickable } - NodeMgr.intialize(options); + NodeMgr.initialize(options); }); }); \ No newline at end of file diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/users.js b/webroot/isle/cdn/scripts-dev/src/app/views/users.js index 71e7f40..a3053ab 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/users.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/users.js @@ -14,11 +14,16 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { var nameText = ''; $.each(retVal['items'], function(index, val){ - nameText = '' + Util.htmlEncode(val['name']) + ''; + nameText = '' + Util.htmlEncode(val['name']) + + ''; if(val['email'] != null) { - nameText += ' '; + nameText += ' '; } - tableHTML += '' + nameText + ''; + tableHTML += '' + + nameText + ''; tableHTML += '' + val['Role_name'] + ''; }); @@ -39,10 +44,12 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { var emailVal = rowData['email']; var roleVal = rowData['role']; - //after the select combo box add the employee name text and a hidden form field and set value to the empno. then remove the combobox from the dom. + // After the select combo box add the employee name text and a hidden form + // field and set value to the empno. then remove the combobox from the dom. $('#labEmail').hide(); $('#readOnlyUser').remove(); $('#modalDialog select[name="' + this.fieldNames['uid'] + '"]').after('' + Util.htmlEncode(nameVal) + ''); +// $('#modalDialog select option[value="' + uidVal + '"]').attr('' + Util.htmlEncode(nameVal) + ''); $('#modalDialog .ui-combobox').hide(); $('#modalDialog input[name="' + this.fieldNames['id'] + '"]').val(idVal); @@ -62,7 +69,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { firstFocus: 'select' } - NodeMgr.intialize(options); + NodeMgr.initialize(options); $('#' + options.fieldNames['uid']).combobox({ selected: function(event, ui) { @@ -73,4 +80,4 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }); }); -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/app/views/versions.js b/webroot/isle/cdn/scripts-dev/src/app/views/versions.js index 2e23802..7db1bbe 100755 --- a/webroot/isle/cdn/scripts-dev/src/app/views/versions.js +++ b/webroot/isle/cdn/scripts-dev/src/app/views/versions.js @@ -58,7 +58,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { //an error occurred on the server. - $('#VerColMenu').html('
I\'m sorry.
Something went wrong.
Feel free to .
'); + $('#VerColMenu').html('
I\'m sorry.
Something went wrong (' + errorThrown + ').
Feel free to .
'); return false; }, success: function(data, textStatus, jqXHR) { @@ -77,7 +77,7 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } } - NodeMgr.intialize(options); + NodeMgr.initialize(options); $('#container').on('click keypress', '#showAll, #VerColMenu span.selector', function(e){ if(e.type == 'click' || (e.type == 'keypress' && e.which == 13)) { @@ -185,4 +185,4 @@ define(["jquery", "../Util", "../NodeManager"], function($, Util, NodeManager) { } }); -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts-dev/src/lib/jquery.combobox.js b/webroot/isle/cdn/scripts-dev/src/lib/jquery.combobox.js index f55491a..057993e 100755 --- a/webroot/isle/cdn/scripts-dev/src/lib/jquery.combobox.js +++ b/webroot/isle/cdn/scripts-dev/src/lib/jquery.combobox.js @@ -26,7 +26,7 @@ var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); var select_el = select.get(0); // get dom element var rep = new Array(); // response array - var maxRepSize = 100; // maximum response size + var maxRepSize = 2000; // maximum response size // simple loop for the options for (var i = 0; i < select_el.length; i++) { var text = select_el.options[i].text; @@ -137,4 +137,4 @@ $.Widget.prototype.destroy.call( this ); } }); -})(jQuery, window, document); \ No newline at end of file +})(jQuery, window, document); diff --git a/webroot/isle/cdn/scripts-dev/src/main.js b/webroot/isle/cdn/scripts-dev/src/main.js index 4ed0b3e..81a6033 100755 --- a/webroot/isle/cdn/scripts-dev/src/main.js +++ b/webroot/isle/cdn/scripts-dev/src/main.js @@ -22,7 +22,7 @@ require(['jquery', 'bootstrap-dropdown', 'bootstrap-modal', 'bootstrap-alert', ' dataType: 'json', dataFilter: Util.parseJSON, error: function(jqXHR, textStatus, errorThrown) { - alert("I'm sorry. Something went wrong."); + alert("I'm sorry. Something went wrong (" + errorThrown + ")."); return false; }, success: function(data, textStatus, jqXHR) { @@ -187,7 +187,8 @@ require(['jquery', 'bootstrap-dropdown', 'bootstrap-modal', 'bootstrap-alert', ' // enable the buttons $("#feedbackDialog .modal-footer button").removeAttr("disabled"); //replace loading text with error text. - $("#feedbackDialog .modal-footer .footerRight").addClass('errorText').html('I\'m sorry. Something went wrong.'); + $("#feedbackDialog .modal-footer .footerRight").addClass('errorText') + .html('I\'m sorry. Something went wrong (' + errorThrown + ').'); var retVal2 = ''; return false; }, @@ -286,4 +287,4 @@ require(['jquery', 'bootstrap-dropdown', 'bootstrap-modal', 'bootstrap-alert', ' break; } } -}); \ No newline at end of file +}); diff --git a/webroot/isle/cdn/scripts/app/views/assetForm.js b/webroot/isle/cdn/scripts/app/views/assetForm.js index 629b467..6fec8f4 100644 --- a/webroot/isle/cdn/scripts/app/views/assetForm.js +++ b/webroot/isle/cdn/scripts/app/views/assetForm.js @@ -1 +1 @@ -define(["jquery","../Util","../NodeManager"],function(e,t,n){e(function(){function r(n){e("#modelDetails").remove();if(n=="")return;e("#msg-selModel").after('

Loading model details loading animation

');var r={};r.categories=[],r.relationships=[],r.attributes=[],r.attachments=[];var i=e("#csrfToken").html();e.when(e.ajax({url:t.rootdir+"remoteInterface",headers:{"x-csrftoken":i},data:{model:"AssetModel",method:"getAll",filter:{cols:[{col:"id",val:n}]}},dataType:"json",dataFilter:t.parseJSON,error:function(t,n,r){return e("#modelDetails").html('
I\'m sorry.
Something went wrong.
Feel free to .
'),!1},success:function(t,n,i){e.each(t.result.value.items,function(e,t){r.url=t.url,r.desc=t.desc,r.img=t.img,r.img_modified=t.img_modified})}}),e.ajax({url:t.rootdir+"remoteInterface",headers:{"x-csrftoken":i},data:{model:"AssetModelCategory",method:"getAll",filter:{cols:[{col:"model",val:n}]}},dataType:"json",dataFilter:t.parseJSON,error:function(t,n,r){return e("#modelDetails").html('
I\'m sorry.
Something went wrong.
Feel free to .
'),!1},success:function(t,n,i){e.each(t.result.value.items,function(e,t){r.categories.push({id:t.category,category:t.Category_name})})}}),e.ajax({url:t.rootdir+"remoteInterface",headers:{"x-csrftoken":i},data:{model:"AssetModelRelation",method:"getAll",filter:{cols:[{col:"source",val:n},{col:"target",val:n}],separator:"OR"}},dataType:"json",dataFilter:t.parseJSON,error:function(t,n,r){return e("#modelDetails").html('
I\'m sorry.
Something went wrong.
Feel free to .
'),!1},success:function(t,n,i){e.each(t.result.value.items,function(e,t){r.relationships.push({sourceId:t.source,source:t.Manufacturer_name+" "+t.AssetModel_model,relation:t.Relation_name,targetId:t.target,target:t.Manufacturer2_name+" "+t.AssetModel2_model})})}}),e.ajax({url:t.rootdir+"remoteInterface",headers:{"x-csrftoken":i},data:{model:"AssetModelAttribute",method:"getAll",filter:{cols:[{col:"model",val:n}]},order:[{colClass:"Attribute",col:"name"},{col:"id"}]},dataType:"json",dataFilter:t.parseJSON,error:function(t,n,r){return e("#modelDetails").html('
I\'m sorry.
Something went wrong.
Feel free to .
'),!1},success:function(t,n,i){var s="",o="",u=1,a="";e.each(t.result.value.items,function(e,n){a="",n["Attribute_name"]==o?(u++,a=" #"+u):e4?s=" "+n.AttributeType_unit:s=""),r.attributes.push({name:n.Attribute_name+a,value:n.value,unit:s})})}}),e.ajax({url:t.rootdir+"remoteInterface",headers:{"x-csrftoken":i},data:{model:"AssetModelAttachment",method:"getAll",filter:{cols:[{col:"model",val:n}]}},dataType:"json",dataFilter:t.parseJSON,error:function(t,n,r){return e("#modelDetails").html('
I\'m sorry.
Something went wrong.
Feel free to .
'),!1},success:function(t,n,i){e.each(t.result.value.items,function(e,t){r.attachments.push({name:t.name,num:t.num,extension:t.extension})})}})).done(function(i,s,o,u,a){e("#modelDetails").html('
Model details loaded.
');var f='
';r.img!==null?f+=''+t.htmlEncode(r.desc)+'
':f+='
No Image
',r.url!==null&&(f+='Website'),f+="
",f+='

'+t.htmlEncode(r.desc)+"

",e.each(r.attributes,function(e,n){f+="

"+t.htmlEncode(n.name)+': '+t.htmlEncode(n.value)+t.htmlEncode(n.unit)+"

"}),f+="

Categories: ",r.categories.length>0?(e.each(r.categories,function(e,n){f+=''+t.htmlEncode(n.category)+", "}),f=f.substring(0,f.length-2)+""):f+='None',f+="

",e.each(r.relationships,function(e,n){f+='

'+t.htmlEncode(n.source)+' '+t.htmlEncode(n.relation)+' '+t.htmlEncode(n.target)+"

"}),f+="

Attachments: ",r.attachments.length>0?(e.each(r.attachments,function(e,r){f+=''+r.name+"."+r.extension+", "}),f=f.substring(0,f.length-2)):f+='None',f+="

",f+="
",e("#modelDetails").html(f)})}e("#selModel").val()!=""&&r(e("#selModel").val()),e("#selModel").change(function(t){r(e(this).val())});if(t.currentPage()!="assets/new"){var i=new n,s={itemName:"asset",modelName:"Asset",itemVal:e("#hidId").val(),postURL:"assets/"+e("#hidId").val(),successFunction:function(e,t,n){window.location="../assets"+querystring}};i.confirmDelete(s),s={modals:!1,fieldNames:[{asset:"hidAssetIdCO",location:"selLocationCO",purpose:"txtPurposeCO",finish:"txtFinishCO",notes:"txtaNotesCO"},{asset:"hidAssetIdCI",notes:"txtaNotesCI"},{asset:"hidAssetIdR",purpose:"txtPurposeR",notes:"txtaNotesR"},{asset:"hidAssetIdUR",notes:"txtaNotesUR"},{id:"hidId",model:"selModel",location:"selLocation",serial:"txtSerial",notes:"txtaNotes"}],limit:10,filter:{cols:[{col:"asset",val:e("#hidId").val()}]},order:[{col:"time",dir:"DESC"}],itemName:"transaction",getCallback:function(n,r){var i=n.items[0];if(n["count"]!=0&&i.TransactionType_name=="Check-out")if(i.User_uid==e("html").attr("data-user")){var s="";i.finish!==null&&(s=t.htmlEncode(e.format.date(t.parseDate(i.finish).toString(),"M/d/yyyy"))),e("#actionsSubSection").html('')}else{var o="";o=''+t.htmlEncode(i.User_name)+"",i.User_email!=null&&(o+=' '),e("#actionsSubSection").html("Out to "+o)}else if(n["count"]!=0&&i.TransactionType_name=="Restrict")e("html").attr("data-role")>=ISLE_CONTRIBUTOR?e("#actionsSubSection").html(''):e("#actionsSubSection").html("Restricted");else if(e("html").attr("data-role")>ISLE_VIEWER){var u="";e("html").attr("data-role")>=ISLE_CONTRIBUTOR&&(u=' '),e("#actionsSubSection").html(''+u)}r&&e("#actionsSubSection button").first().focus()},buildTable:function(n){var r="TimeActionUserLocationPurposeEst. Finish DateNotes",i="";e.each(n.items,function(n,s){r+=""+t.htmlEncode(e.format.date(s.time,"M/d/yyyy h:mm a"))+"",r+=""+t.htmlEncode(s.TransactionType_name)+"",s["User_email"]==null?i=t.htmlEncode(s.User_name):i=''+t.htmlEncode(s.User_name)+"",r+=""+i+"",r+=""+t.htmlEncode(s.Location_center)+" "+t.htmlEncode(s.Location_bldg)+"-"+t.htmlEncode(s.Location_room)+"",r+=""+t.htmlEncode(s.purpose)+"",!s.finish||s["finish"].indexOf("00")==0?r+="":r+=""+t.htmlEncode(e.format.date(t.parseDate(s.finish).toString(),"M/d/yyyy"))+"",r+=""+t.htmlEncode(s.notes)+""}),r+="",e("#nodeTable").html(r)}},i.intialize(s),e("#"+s.fieldNames[0].finish).datepicker({showOn:"button",buttonImage:t.rootdir+"cdn/images/calendar.gif"}),e("#transData").slideUp(1),e("#VerColMenu li h4").on("click keypress",function(t){if(t.type=="click"||t.type=="keypress"&&t.which==13)e(this).children("span.expander").html()==="+"?e(this).children("span.expander").html("-"):e(this).children("span.expander").html("+"),e(this).next().slideToggle("fast")})}if(e("html").attr("data-role")>=ISLE_CONTRIBUTOR){var o=new n,u={fieldNames:{id:"id",center:"selCenter",bldg:"txtBldg",room:"txtRoom"},itemName:"location",addBtnId:"addLocationBtn",dialogId:"modalDialogLocation",formId:"modalFormLocation",hasTable:!1,duplicate:{field:"room",errorMsg:"This location already exists"},successCallback:function(n){e("#selLocation option").first().after('