Example #1
0
 public function __construct(w2p_Core_CAppUI $AppUI, w2p_Core_BaseObject $object, $noun)
 {
     $this->AppUI = $AppUI;
     $this->object = $object;
     $this->noun = $noun;
     $this->action = '?m=' . w2p_pluralize(strtolower($noun));
     $this->dosql = 'do_' . strtolower($noun) . '_aed';
     $this->key = strtolower($noun) . '_id';
 }
 public function addField($fieldName, $fieldValue)
 {
     if ('' == $fieldValue) {
         return '-';
     }
     $pieces = explode('_', $fieldName);
     $suffix = end($pieces);
     switch ($suffix) {
         case 'datetime':
             $myDate = intval($fieldValue) ? new w2p_Utilities_Date($this->AppUI->formatTZAwareTime($fieldValue, '%Y-%m-%d %T')) : null;
             $output = $myDate ? $myDate->format($this->dtf) : '-';
             break;
         case 'email':
             $output = w2p_email($fieldValue);
             break;
         case 'url':
             $value = str_replace(array('"', '"', '<', '>'), '', $fieldValue);
             $output = w2p_url($value);
             break;
         case 'owner':
             if (!$fieldValue) {
                 return '-';
             }
             $obj = new CContact();
             $obj->findContactByUserid($fieldValue);
             $link = '?m=users&a=view&user_id=' . $fieldValue;
             $output = '<a href="' . $link . '">' . $obj->contact_display_name . '</a>';
             break;
         case 'percent':
             $output = round($fieldValue) . '%';
             break;
         case 'description':
             $output = w2p_textarea($fieldValue);
             break;
         case 'company':
         case 'department':
         case 'project':
             $class = 'C' . ucfirst($suffix);
             $obj = new $class();
             $obj->load($fieldValue);
             $link = '?m=' . w2p_pluralize($suffix) . '&a=view&' . $suffix . '_id=' . $fieldValue;
             $output = '<a href="' . $link . '">' . $obj->{"{$suffix}" . '_name'} . '</a>';
             break;
         default:
             $output = htmlspecialchars($fieldValue, ENT_QUOTES);
     }
     return $output;
 }
 public function test_w2p_pluralize()
 {
     $this->assertEquals('projects', w2p_pluralize('project'));
     $this->assertEquals('links', w2p_pluralize('link'));
     $this->assertEquals('companies', w2p_pluralize('company'));
     $this->assertEquals('holidays', w2p_pluralize('holiday'));
     $this->assertEquals('todos', w2p_pluralize('todo'));
 }
 /**
  * createColumn is handy because it can take any input $fieldName and use
  *   its suffix to determine how the field should be displayed.
  *
  * This allows us to treat project_description, task_description,
  *   company_description, or even some_other_crazy_wacky_description in
  *   exactly the same way without additional lines of code or configuration.
  *   If you want to do your own, feel free... but this is probably easier.
  * 
  * Examples: _budget, _date, _name, _owner
  * 
  * This may not work for things like company_type or project_type which are
  *   actually just references to look up tables, ... but should work on
  *   fields like project_company, dept_company because we still have a 
  *   common suffix.
  *
  * @note I'm kind of annoyed about the complexity and sheer number of
  *   paths of this method but overall I think it's laid out reasonably
  *   well. I think the more important part is that I've been able to
  *   encapsulate it all here instead of spreading it all over the modules
  *   and views.
  */
 public function createCell($fieldName, $value, $custom = array())
 {
     $additional = '';
     if ('' == $value) {
         return '<td>-</td>';
     }
     $pieces = explode('_', $fieldName);
     $prefix = $pieces[0];
     $suffix = '_' . end($pieces);
     if ($fieldName == 'project_actual_end_date') {
         $suffix = '_actual';
     }
     switch ($suffix) {
         //BEGIN: object-based linkings
         /*
          * TODO: The following cases are likely to change once we have an approach to 
          *   handle module-level objects and their proper mapping/linkings.
         */
         case '_company':
         case '_contact':
         case '_task':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             $link = '?m=' . w2p_pluralize($module) . '&a=view&' . $module . '_id=' . $value;
             $cell = '<a href="' . $link . '">' . $obj->{"{$module}" . '_name'} . '</a>';
             $suffix .= ' _name';
             break;
         case '_department':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             /**
              * This is a branch separate from _company, _contact, etc above because although the module is called
              *   departments, the fields are dept_id and dept_name. :(
              *                                                              ~ caseydk, Dec 11 2013
              */
             $link = '?m=' . w2p_pluralize($module) . '&a=view&dept_id=' . $value;
             $cell = '<a href="' . $link . '">' . $obj->dept_name . '</a>';
             $suffix .= ' _name';
             break;
         case '_folder':
             $obj = new CFile_Folder();
             $obj->load($value);
             $foldername = $value ? $obj->file_folder_name : 'Root';
             $image = '<img src="' . w2PfindImage('folder5_small.png', 'files') . '" />';
             $link = '?m=files&tab=4&folder=' . (int) $value;
             $cell = '<a href="' . $link . '">' . $image . ' ' . $foldername . '</a>';
             $suffix .= ' _name';
             break;
         case '_user':
         case '_username':
             $obj = new CContact();
             $obj->findContactByUserid($this->tableRowData['user_id']);
             $link = '?m=users&a=view&user_id=' . $this->tableRowData['user_id'];
             $cell = '<a href="' . $link . '">' . $obj->user_username . '</a>';
             break;
             //END: object-based linkings
             /*
              * TODO: These two prefix adjustments are an ugly hack because our departments 
              *   table doesn't follow the same convention as every other table we have. 
              *   This needs to be fixed in v4.0 - caseydk 13 Feb 2012
              *
              * TODO: And unfortunately, the forums module is screwy using 'viewer' instead 
              *   of our standard 'view' for the page. ~ caseydk 16 Feb 2012
             */
         //END: object-based linkings
         /*
          * TODO: These two prefix adjustments are an ugly hack because our departments 
          *   table doesn't follow the same convention as every other table we have. 
          *   This needs to be fixed in v4.0 - caseydk 13 Feb 2012
          *
          * TODO: And unfortunately, the forums module is screwy using 'viewer' instead 
          *   of our standard 'view' for the page. ~ caseydk 16 Feb 2012
         */
         case '_name':
             $prefix = $prefix == 'project_short' ? 'project' : $prefix;
             $prefix = $prefix == 'dept' ? 'department' : $prefix;
             $page = $prefix == 'forum' || $prefix == 'message' ? 'viewer' : 'view';
             $link = '?m=' . w2p_pluralize($prefix) . '&a=' . $page . '&';
             $link = $prefix == 'message' ? '?m=forums&a=' . $page . '&' : $link;
             $prefix = $prefix == 'department' ? 'dept' : $prefix;
             $link .= $prefix . '_id=' . $this->tableRowData[$prefix . '_id'];
             $link .= $prefix == 'task_log' ? '&tab=1&task_id=' . $this->tableRowData['task_id'] : '';
             $icon = $fieldName == 'file_name' ? '<img src="' . w2PfindImage(getIcon($this->tableRowData['file_type']), 'files') . '" />&nbsp;' : '';
             $cell = '<a href="' . $link . '">' . $icon . $value . '</a>';
             //TODO: task_logs are another oddball..
             $cell = $prefix == 'task_log' ? str_replace('task_logs', 'tasks', $cell) : $cell;
             break;
         case '_author':
         case '_creator':
         case '_owner':
         case '_updator':
             if ((int) $value) {
                 $obj = new CContact();
                 $obj->findContactByUserid($value);
                 $suffix .= ' nowrap';
                 $link = '?m=users&a=view&user_id=' . $value;
                 $cell = '<a href="' . $link . '">' . $obj->contact_display_name . '</a>';
             } else {
                 $cell = $value;
             }
             break;
             // The above are all contact/user display names, the below are numbers.
         // The above are all contact/user display names, the below are numbers.
         case '_count':
         case '_hours':
             $cell = $value;
             break;
         case '_duration':
             $durnTypes = w2PgetSysVal('TaskDurationType');
             $cell = $value . ' ' . $this->AppUI->_($durnTypes[$this->tableRowData['task_duration_type']]);
             break;
         case '_size':
             $cell = file_size($value);
             break;
         case '_budget':
             $cell = w2PgetConfig('currency_symbol');
             $cell .= formatCurrency($value, $this->AppUI->getPref('CURRENCYFORM'));
             break;
         case '_url':
             $value = str_replace(array('"', '"', '<', '>'), '', $value);
             $cell = w2p_url($value);
             break;
         case '_email':
             $cell = w2p_email($value);
             break;
         case '_birthday':
         case '_date':
             $myDate = intval($value) ? new w2p_Utilities_Date($value) : null;
             $cell = $myDate ? $myDate->format($this->df) : '-';
             break;
         case '_actual':
             $end_date = intval($this->tableRowData['project_end_date']) ? new w2p_Utilities_Date($this->tableRowData['project_end_date']) : null;
             $actual_end_date = intval($this->tableRowData['project_actual_end_date']) ? new w2p_Utilities_Date($this->tableRowData['project_actual_end_date']) : null;
             $style = $actual_end_date < $end_date && !empty($end_date) ? 'style="color:red; font-weight:bold"' : '';
             if ($actual_end_date) {
                 $cell = '<a href="?m=tasks&a=view&task_id=' . $this->tableRowData['project_last_task'] . '" ' . $style . '>' . $actual_end_date->format($this->df) . '</a>';
             } else {
                 $cell = '-';
             }
             break;
         case '_created':
         case '_datetime':
         case '_update':
         case '_updated':
             $myDate = intval($value) ? new w2p_Utilities_Date($this->AppUI->formatTZAwareTime($value, '%Y-%m-%d %T')) : null;
             $cell = $myDate ? $myDate->format($this->dtf) : '-';
             break;
         case '_description':
             $cell = w2p_textarea($value);
             break;
         case '_priority':
             $mod = $value > 0 ? '+' : '-';
             $image = '<img src="' . w2PfindImage('icons/priority' . $mod . abs($value) . '.gif') . '" width="13" height="16" alt="">';
             $cell = $value != 0 ? $image : '';
             break;
         case '_complete':
         case '_assignment':
         case '_allocated':
         case '_allocation':
             $cell = round($value) . '%';
             break;
         case '_password':
             $cell = '(' . $this->AppUI->_('hidden') . ')';
             break;
         case '_version':
             $value = (int) (100 * $value);
             $cell = number_format($value / 100, 2);
             break;
         case '_identifier':
             $additional = 'style="background-color:#' . $value . '; color:' . bestColor($value) . '" ';
             $cell = $this->tableRowData['project_percent_complete'] . '%';
             break;
         case '_project':
             $module = substr($suffix, 1);
             $class = 'C' . ucfirst($module);
             $obj = new $class();
             $obj->load($value);
             $color = $obj->project_color_identifier;
             $link = '?m=' . w2p_pluralize($module) . '&a=view&' . $module . '_id=' . $value;
             $cell = '<span style="background-color:#' . $color . '; padding: 3px"><a href="' . $link . '" style="color:' . bestColor($color) . '">' . $obj->{"{$module}" . '_name'} . '</a></span>';
             $suffix .= ' _name';
             break;
         case '_assignees':
             $cell = $value;
             break;
         case '_problem':
             if ($value) {
                 $cell = '<a href="?m=tasks&a=index&f=all&project_id=' . $this->tableRowData['project_id'] . '">';
                 $cell .= w2PshowImage('icons/dialog-warning5.png', 16, 16, 'Problem', 'Problem');
                 $cell .= '</a>';
             } else {
                 $cell = '-';
             }
             break;
         default:
             $value = isset($custom[$fieldName]) ? $custom[$fieldName][$value] : $value;
             $cell = htmlspecialchars($value, ENT_QUOTES);
     }
     $begin = '<td ' . $additional . 'class="' . $suffix . '">';
     $end = '</td>';
     return $begin . $cell . $end;
 }
 protected function _buildCells($array = array())
 {
     $cells = '';
     /**
      * Note: We can't refactor the actual td/class stuff out to the return statement because we may have multiple
      *   inserted cells processed together.. and we need them to remain separate cells.
      */
     foreach ($array as $type => $value) {
         switch ($type) {
             case 'edit':
                 // @note This module determination *only* works if you've followed our naming conventions.
                 $pieces = explode('_', $value);
                 $module = w2p_pluralize($pieces[0]);
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<a href="./index.php?m=' . $module . '&a=addedit&' . $value . '=' . $this->tableRowData[$value] . '">' . w2PshowImage('icons/stock_edit-16.png', '16', '16') . '</a>';
                 $contents .= '</td>';
                 break;
             case 'select':
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<input type="checkbox" value="' . $this->tableRowData[$value] . '" name="' . $value . '[]" />';
                 $contents .= '</td>';
                 break;
             case 'log':
                 $pieces = explode('_', $value);
                 $module = w2p_pluralize($pieces[0]);
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<a href="./index.php?m=' . $module . '&a=view&tab=1&' . $value . '=' . $this->tableRowData[$value] . '">' . w2PshowImage('icons/edit_add.png', '16', '16') . '</a>';
                 $contents .= '</td>';
                 break;
             case 'pin':
                 $image = $this->tableRowData['task_pinned'] ? 'pin.gif' : 'unpin.gif';
                 $pieces = explode('_', $value);
                 $module = w2p_pluralize($pieces[0]);
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<a href="./index.php?m=' . $module . '&pin=1&' . $value . '=' . $this->tableRowData[$value] . '">' . w2PshowImage('icons/' . $image, '16', '16') . '</a>';
                 $contents .= '</td>';
                 break;
             case 'url':
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<a href="' . $this->tableRowData[$value] . '" target="_blank">' . w2PshowImage('forward.png', '16', '16') . '</a>';
                 $contents .= '</td>';
                 break;
             case 'watch':
                 $contents = '<td class="_' . $type . '">';
                 $contents .= '<input type="checkbox" name="forum_' . $this->tableRowData[$value] . '"' . ($this->tableRowData['watch_user'] ? 'checked="checked"' : '') . ' />';
                 $contents .= '</td>';
                 break;
             default:
                 $contents = '<td></td>';
         }
         $cells .= $contents;
     }
     return $cells;
 }
function w2p_autoload($class_name)
{
    global $AppUI;
    $name = $class_name;
    if (false !== strpos($name, 'w2p_')) {
        $name = str_replace('_', DIRECTORY_SEPARATOR, $name);
        $classpath = W2P_BASE_DIR . '/classes/' . $name . '.class.php';
        require_once $classpath;
        return;
    }
    $name = strtolower($class_name);
    switch ($name) {
        case 'libmail':
            // Deprecated as of v2.3
            //TODO: remove this in v4.0
            require_once W2P_BASE_DIR . '/classes/mail.class.php';
            break;
        case 'w2pacl':
            // Deprecated as of v3.0
            //TODO: remove this in v4.0
            require_once W2P_BASE_DIR . '/classes/permissions.class.php';
            break;
        case 'cappui':
            // Deprecated as of v3.0
            //TODO: remove this in v4.0
            require_once W2P_BASE_DIR . '/classes/ui.class.php';
            break;
        case 'xajax':
            require_once W2P_BASE_DIR . '/lib/xajax/xajax_core/xajax.inc.php';
            break;
        case 'w2pajaxresponse':
            // Deprecated as of v3.0
            //TODO: remove this in v4.0
            require_once W2P_BASE_DIR . '/classes/ajax.class.php';
            break;
            /*
             * The following are all wirings for module classes that don't follow
             * our naming conventions.
             */
        /*
         * The following are all wirings for module classes that don't follow
         * our naming conventions.
         */
        case 'cevent':
            require_once W2P_BASE_DIR . '/modules/calendar/calendar.class.php';
            break;
        case 'cuser':
            require_once W2P_BASE_DIR . '/modules/admin/admin.class.php';
            break;
        case 'cfilefolder':
            require_once W2P_BASE_DIR . '/modules/files/filefolder.class.php';
            break;
        case 'ctasklog':
            require_once W2P_BASE_DIR . '/modules/tasks/tasklogs.class.php';
            break;
        case 'cforummessage':
            require_once W2P_BASE_DIR . '/modules/forums/forummessage.class.php';
            break;
        case 'cprojectdesigneroptions':
            require_once W2P_BASE_DIR . '/modules/projectdesigner/projectdesigner.class.php';
            break;
        case 'crole':
            require_once W2P_BASE_DIR . '/modules/system/roles/roles.class.php';
            break;
        case 'csyskey':
            require_once W2P_BASE_DIR . '/modules/system/syskeys/syskeys.class.php';
            break;
        case 'bcode':
            require_once W2P_BASE_DIR . '/modules/system/system.class.php';
            break;
        case 'chistory':
            require_once W2P_BASE_DIR . '/modules/history/history.class.php';
            break;
        default:
            if (file_exists(W2P_BASE_DIR . '/classes/' . $name . '.class.php')) {
                require_once W2P_BASE_DIR . '/classes/' . $name . '.class.php';
                return;
            }
            if ($name[0] == 'c') {
                $name = substr($name, 1);
            }
            if (file_exists(W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.class.php')) {
                require_once W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.class.php';
                return;
            }
            if (!in_array($name, array('system'))) {
                $name = w2p_pluralize($name);
            }
            if (file_exists(W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.class.php')) {
                require_once W2P_BASE_DIR . '/modules/' . $name . '/' . $name . '.class.php';
                return;
            }
            break;
    }
}
 /**
  * @param $m
  * @param $id
  * @param string $a
  */
 public function addViewLink($module, $key, $a = 'view')
 {
     if ($key) {
         $this->addCrumb('?m=' . w2p_pluralize($module) . '&a=' . $a . '&' . $module . '_id=' . $key, 'view this ' . $module);
     }
 }
 public function addField($fieldName, $fieldValue, $options = array(), $values = array())
 {
     $pieces = explode('_', $fieldName);
     $suffix = end($pieces);
     $params = '';
     foreach ($options as $key => $value) {
         $params .= $key . '="' . $value . '" ';
     }
     switch ($suffix) {
         case 'company':
             $class = 'C' . ucfirst($suffix);
             $obj = new $class();
             $obj->load($fieldValue);
             $link = '?m=' . w2p_pluralize($suffix) . '&a=view&' . $suffix . '_id=' . $fieldValue;
             $output = '<a href="' . $link . '">' . $obj->{"{$suffix}" . '_name'} . '</a>';
             break;
         case 'desc':
             // @todo This is a special case because department->dept_notes should be renamed department->dept_description
         // @todo This is a special case because department->dept_notes should be renamed department->dept_description
         case 'note':
             // @todo This is a special case because resource->resource_note should be renamed resource->resource_description
         // @todo This is a special case because resource->resource_note should be renamed resource->resource_description
         case 'notes':
             // @todo This is a special case because contact->contact_notes should be renamed contact->contact_description
         // @todo This is a special case because contact->contact_notes should be renamed contact->contact_description
         case 'signature':
             // @todo This is a special case because user->user_signature should be renamed to something else..?
         // @todo This is a special case because user->user_signature should be renamed to something else..?
         case 'description':
             $output = '<textarea name="' . $fieldName . '" class="' . $suffix . '">' . w2PformSafe($fieldValue) . '</textarea>';
             break;
         case 'birthday':
             // @todo This is a special case because contact->contact_birthday should be renamed contact->contact_birth_date
             $myDate = intval($fieldValue) ? new w2p_Utilities_Date($fieldValue) : null;
             $date = $myDate ? $myDate->format('%Y-%m-%d') : '-';
             $output = '<input type="text" class="text ' . $suffix . '" ';
             $output .= 'name="' . $fieldName . '" value="' . w2PformSafe($date) . '" ' . $params . ' />';
             break;
         case 'date':
             $date = $fieldValue ? new w2p_Utilities_Date($fieldValue) : null;
             unset($pieces[0]);
             $datename = implode('_', $pieces);
             $output = '<input type="hidden" name="' . $fieldName . '" id="' . $fieldName . '" value="' . ($date ? $date->format(FMT_TIMESTAMP_DATE) : '') . '" />';
             $output .= '<input type="text" name="' . $datename . '" id="' . $datename . '" onchange="setDate_new(\'editFrm\', \'' . $datename . '\');" value="' . ($date ? $date->format($this->df) : '') . '" class="text" />';
             $output .= '<a href="javascript: void(0);" onclick="return showCalendar(\'' . $datename . '\', \'' . $this->df . '\', \'editFrm\', null, true, true)">';
             $output .= '<img src="' . w2PfindImage('calendar.gif') . '" alt="' . $this->AppUI->_('Calendar') . '" />';
             $output .= '</a>';
             break;
         case 'private':
         case 'updateask':
             // @todo This is unique to the contacts module
             $output = '<input type="checkbox" value="1" class="text ' . $suffix . '" ';
             $output .= 'name="' . $fieldName . '" ' . $params . ' />';
             break;
         case 'parent':
             // @note This drops through on purpose
             $suffix = 'department';
         case 'allocation':
         case 'category':
         case 'country':
         case 'owner':
         case 'priority':
         case 'project':
         case 'status':
         case 'type':
             $output = arraySelect($values, $fieldName, 'size="1" class="text ' . $suffix . '"', $fieldValue);
             break;
         case 'url':
             $output = 'http://<input type="text" class="text ' . $suffix . '" ';
             $output .= 'name="' . $fieldName . '" value="' . w2PformSafe($fieldValue) . '" ' . $params . ' />';
             $output .= '<a href="javascript: void(0);" onclick="testURL()">[' . $this->AppUI->_('test') . ']</a>';
             break;
             /**
              * This handles the default input text input box. It currently covers these fields:
              *   all names, email, phone1, phone2, url, address1, address2, city, state, zip, fax, title, job
              */
         /**
          * This handles the default input text input box. It currently covers these fields:
          *   all names, email, phone1, phone2, url, address1, address2, city, state, zip, fax, title, job
          */
         default:
             $output = '<input type="text" class="text ' . $suffix . '" ';
             $output .= 'name="' . $fieldName . '" value="' . w2PformSafe($fieldValue) . '" ' . $params . ' />';
     }
     return $output;
 }