public function preview()
    {
        global $AppUI;
        $perms =& $AppUI->acl();
        $output = '';
        $data = $this->scrubbedData;
        $tree = xmlParse($data);
        $i = 0;
        if ((int) $tree[0]['children'][0]['cdata']) {
            $i = 1;
        }
        $project_name = str_replace('.xml', '', $tree[0]['children'][$i]['cdata']);
        $tree = rebuildTree($tree);
        $tree = $tree['PROJECT'][0];
        $output .= '
            <script type="text/javascript" src="' . $base . 'js/utils.js"></script>

            <script type="text/javascript">
                function ToggleUserFields() {
                    userFields = document.getElementsByName("userRelated");
                    for (i=0; i<userFields.length; i++) {
                        if (userFields[i].style.visibility == "hidden") {
                            userFields[i].style.visibility = "visible";
                        } else {
                            userFields[i].style.visibility = "hidden";
                        }
                    }
                }

                function addNew_choice(selection) {
                    var selValue = selection.options[selection.selectedIndex].text;
                    return selValue == "Add New";
                }

                function valid(menu, txt) {
                    if (txt.value == "") {
                        if (addNew_choice(menu)) {
                            alert("You need to type the user name to add into the text box");
                            return false;
                        } else {
                            return true;
                        }
                    } else {
                        if (!addNew_choice(menu)) {
                            alert("Incompatible selection");
                            return false;
                        } else {
                            return true;
                        }
                    }
                }

                function activateTxtFld(field) {
                    field.style.visibility  = "visible";
                    field.focus();
                }

                function process_input(textfield) {
                    var parents = getParent(textfield, "tr");
                    var selRow = (parents ? parents[0] : null);
                    var selection = selRow.cells[1].children[0];
                    adjust_task_users(selection.name.match(/\\d+/)[0], textfield.value);
                }

                function process_choice(selection) {
                    var parents = getParent(selection, "tr");
                    var selRow = (parents ? parents[0] : null);
                    var textfield = selRow.cells[2].children[0];

                    if (addNew_choice(selection)) {
                        if (typeof textfield != "undefined") {
                            activateTxtFld(textfield);
                        }
                    } else {
                        if (typeof textfield != "undefined") {
                            textfield.style.visibility  = "hidden";
                            textfield.value = "";
                        }
                        adjust_task_users(selection.name.match(/\\d+/)[0], selection.options[selection.selectedIndex].text);
                    }
                }

                function check_choice(textfield) {
                    var parents = getParent(textfield, "tr");
                    var selRow = (parents ? parents[0] : null);
                    var menu = selRow.cells[1].children[0];

                    if (!addNew_choice(menu)) {
                        textfield.blur();
                        alert("Please check your menu selection first");
                        menu.focus();
                    }
                }

                function adjust_task_users(uid, newText) {
                    var selects = document.getElementsByTagName("select");

                    if (selects) {
                        for (var i=0; i < selects.length; i++) {
                            var selName = selects[i].name;
                            if (selName.search(/^tasks\\[\\d+\\]\\[resources\\]\\[\\]/) != -1) {
                                var taskuser = selects[i];
                                for (var j=0; j < taskuser.options.length; j++){
                                    if (taskuser.options[j].value == uid) {
                                        taskuser.options[j].text = newText;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            </script>
            <table width="100%">
            <tr>
            <td align="right">' . $AppUI->_('Company Name') . ':</td>';
        $output .= $this->_createCompanySelection($AppUI, $tree['COMPANY']);
        $output .= $this->_createProjectSelection($AppUI, $project_name);
        $users = $perms->getPermittedUsers('projects');
        $output .= '<tr><td align="right">' . $AppUI->_('Project Owner') . ':</td><td>';
        $output .= arraySelect($users, 'project_owner', 'size="1" style="width:200px;" class="text"', $AppUI->user_id);
        $output .= '<td/></tr>';
        $pstatus = w2PgetSysVal('ProjectStatus');
        $output .= '<tr><td align="right">' . $AppUI->_('Project Status') . ':</td><td>';
        $output .= arraySelect($pstatus, 'project_status', 'size="1" class="text"', $row->project_status, true);
        $output .= '<td/></tr>';
        $output .= '
            <tr>
                <td align="right">' . $AppUI->_('Start Date') . ':</td>
                <td><input type="text" name="project_start_date" value="%%STARTDATE%%" /></td>
            </tr>
            <tr>
                <td align="right">' . $AppUI->_('End Date') . ':</td>
                <td><input type="text" name="project_end_date" value="' . $tree['FINISHDATE'] . '" /></td>
            </tr>
            <tr>
                <td align="right">' . $AppUI->_('Do Not Import Users') . ':</td>
                <td><input type="checkbox" name="nouserimport" value="true" onclick="ToggleUserFields()" /></td>
            </tr>
            <tr>
                <td colspan="2">' . $AppUI->_('Users') . ':</td>
            </tr>
            <tr>
                <td colspan="2"><div name="userRelated"><br /><em>' . $AppUI->_('userinfo') . '</em>
            <table>';
        $q = new DBQuery();
        $q->addQuery('u.*,co.*,concat(co.contact_first_name,\' \',co.contact_last_name) as full_name,comp.company_name');
        $q->addTable('users', 'u');
        $q->addJoin('contacts', 'co', 'co.contact_id = u.user_contact', 'inner');
        $q->addJoin('companies', 'comp', 'comp.company_id=co.contact_company');
        $q->addOrder('co.contact_first_name, co.contact_last_name');
        $workers = $q->loadList();
        $percent = array(0 => '0', 5 => '5', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30', 35 => '35', 40 => '40', 45 => '45', 50 => '50', 55 => '55', 60 => '60', 65 => '65', 70 => '70', 75 => '75', 80 => '80', 85 => '85', 90 => '90', 95 => '95', 100 => '100');
        $q = new DBQuery();
        // Users (Resources)
        $resources = array();
        $resources[0] = '';
        foreach ($tree['RESOURCES'][0]['RESOURCE'] as $r) {
            $q->clear();
            $q->addQuery('user_id');
            $q->addTable('users');
            $q->leftJoin('contacts', 'c', 'user_contact = contact_id');
            $myusername = mysql_real_escape_string(strtolower($r['NAME']));
            $q->addWhere("LOWER(user_username) LIKE '{$myusername}' OR LOWER(CONCAT_WS(' ', contact_first_name, contact_last_name)) = '{$myusername}'");
            $r['LID'] = $q->loadResult();
            if (!empty($myusername)) {
                $output .= '
                    <tr>
                    <td>' . $AppUI->_('User name') . ': </td>
                    <td align="left">
                    <select name="users[' . $r['UID'] . '][user_userselect]" onChange="process_choice(this);">';
                if (empty($r['LID'])) {
                    $resources[$r['UID']] = ucwords(strtolower($r['NAME']));
                    $output .= '
                    <option value="-1" selected>' . $AppUI->_('Add New') . '</option>\\n';
                }
                foreach ($workers as $user) {
                    if (!empty($r['LID']) && $user["user_id"] == $r['LID']) {
                        $resources[$r['UID']] = $user["contact_first_name"] . ' ' . $user["contact_last_name"];
                    }
                    $output .= '<option value="' . $user["user_id"] . '"' . (!empty($r['LID']) && $user["user_id"] == $r['LID'] ? "selected" : "") . '>' . $user["contact_first_name"] . ' ' . $user["contact_last_name"] . '</option>\\n';
                }
                $output .= '</select></td><td>';
                if (empty($r['LID'])) {
                    $output .= '<input type="text" name="users[' . $r['UID'] . '][user_username]" value="' . ucwords(strtolower($r['NAME'])) . '" onfocus="check_choice(this)" onChange="process_input(this);"/>';
                } else {
                    $output .= '&nbsp;';
                }
                $output .= '</td><td>(' . $AppUI->_('Resource') . ' UID ' . $r['UID'] . ')</td>';
                if (empty($r['LID'])) {
                    if (function_exists('w2PUTF8strlen')) {
                        if (w2PUTF8strlen($r['NAME']) < w2PgetConfig('username_min_len')) {
                            $output .= ' <em>' . $AppUI->_('username_min_len.') . '</em>';
                        }
                    } else {
                        if (strlen($r['NAME']) < w2PgetConfig('username_min_len')) {
                            $output .= ' <em>' . $AppUI->_('username_min_len.') . '</em>';
                        }
                    }
                }
                $output .= '</td></tr>';
            }
        }
        // Insert Tasks
        $output .= '
            </table>
            </div></td></tr>';
        $output .= '
            <tr>
            <td colspan="2">' . $AppUI->_('Tasks') . ':</td>
            </tr>
            <tr>
            <td colspan="2">
            <table width="100%" style="border-collapse:collapse;">
            <tr>
            <th></th>
            <th>' . $AppUI->_('Name') . '</th>
            <th>' . $AppUI->_('Start Date') . '</th>
            <th>' . $AppUI->_('End Date') . '</th>
            <th>' . $AppUI->_('user allocations') . '</th>
            </tr>';
        $taskCount = 0;
        foreach ($tree['TASKS'][0]['TASK'] as $k => $task) {
            if ($task['UID'] != 0 && trim($task['NAME']) != '') {
                $output .= '<tr style="border:1px solid #000; margin-bottom:4px;"><td>';
                $output .= '<input type="hidden" name="tasks[' . $k . '][UID]" value="' . $task['UID'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][OUTLINENUMBER]" value="' . $task['OUTLINENUMBER'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_name]" value="' . $task['NAME'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_description]" value="' . $task['NOTES'] . '" />';
                $priority = $task['PRIORITY'] > 0 ? 1 : 0;
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_priority]" value="' . $priority . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_start_date]" value="' . $task['START'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_end_date]" value="' . $task['FINISH'] . '" />';
                if ($taskCount == 0) {
                    $output = str_replace('%%STARTDATE%%', $task['START'], $output);
                }
                $myDuration = $this->_calculateWork($task['REGULARWORK'], $task['DURATION']);
                $percentComplete = isset($task['PERCENTCOMPLETE']) ? $task['PERCENTCOMPLETE'] : 0;
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_duration]" value="' . $myDuration . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_percent_complete]" value="' . $percentComplete . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_description]" value="' . $task['NOTES'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_dynamic]" value="' . $task['TYPE'] . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_owner]" value="' . $AppUI->user_id . '" />';
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_type]" value="0" />';
                $milestone = $task['MILESTONE'] == '1' ? 1 : 0;
                $output .= '<input type="hidden" name="tasks[' . $k . '][task_milestone]" value="' . $milestone . '" />';
                if (is_array($task['PREDECESSORLINK'])) {
                    foreach ($task['PREDECESSORLINK'] as $dependency) {
                        $output .= '<input type="hidden" name="tasks[' . $k . '][dependencies][]" value="' . $dependency['PREDECESSORUID'] . '" />';
                    }
                }
                $output .= '</td><td>';
                $tasklevel = substr_count($task['OUTLINENUMBER'], '.');
                for ($i = 0; $i < $tasklevel; $i++) {
                    $output .= w2PshowImage(w2PfindImage('corner-dots.gif')) . '&nbsp;';
                }
                $output .= $task['NAME'];
                if ($milestone) {
                    $output .= '<img src="' . w2PfindImage('icons/milestone.gif', $m) . '" border="0" />';
                }
                if (!empty($task['NOTES'])) {
                    $output .= '<br /><hr />' . $task['NOTES'] . '<hr size="2" />';
                }
                $output .= '</td>
                    <td>' . $task['START'] . '</td>
                    <td>' . $task['FINISH'] . '</td>
                    <td>';
                foreach ($tree['ASSIGNMENTS'][0]['ASSIGNMENT'] as $a) {
                    if ($a['TASKUID'] == $task['UID']) {
                        if ($this->_calculateWork($task['REGULARWORK'], $task['DURATION']) > 0) {
                            $perc = 100 * $a['UNITS'];
                        }
                        $output .= '<div name="userRelated">';
                        $output .= arraySelect($resources, 'tasks[' . $k . '][resources][]', '', $a['RESOURCEUID']);
                        $output .= '&nbsp;';
                        $output .= arraySelect($percent, 'tasks[' . $k . '][resources_alloc][]', 'size="1" class="text"', intval(round($perc / 5)) * 5) . '%';
                        $output .= '</div>';
                    }
                }
                $taskCount++;
                $output .= '</td></tr>';
            }
        }
        $output .= '</table></td></tr>';
        $output .= '</table>';
        return $output;
    }
Beispiel #2
0
 public function preview()
 {
     //The whole preview is based on the SimpleXML. It was a easier decision to get atributes from the
     //wbs files and it actually worked! I tried XMLReader but i've failed completely
     global $AppUI;
     $perms =& $AppUI->acl();
     $output = '';
     $data = $this->scrubbedData;
     $reader = simplexml_load_string($data);
     $project_name = $reader->proj->summary['Title'];
     if (empty($project_name)) {
         $project_name = $this->proName;
     }
     $q = new DBQuery();
     $output .= '
       <table width="100%">
       <tr>
       <td align="right">' . $AppUI->_('Company Name') . ':</td>';
     $projectClass = new CProject();
     $output .= $this->_createCompanySelection($AppUI, $tree['COMPANY']);
     $output .= $this->_createProjectSelection($AppUI, $project_name);
     $users = $perms->getPermittedUsers('projects');
     $output .= '<tr><td align="right">' . $AppUI->_('Project Owner') . ':</td><td>';
     $output .= arraySelect($users, 'project_owner', 'size="1" style="width:200px;" class="text"', $AppUI->user_id);
     $output .= '<td/></tr>';
     $pstatus = w2PgetSysVal('ProjectStatus');
     $output .= '<tr><td align="right">' . $AppUI->_('Project Status') . ':</td><td>';
     $output .= arraySelect($pstatus, 'project_status', 'size="1" class="text"', $row->project_status, true);
     $output .= '<td/></tr>';
     $output .= '
       <tr>
         <td align="right">' . $AppUI->_('Start Date') . ':</td>
         <td><input type="text" name="project_start_date" value="' . $reader->proj->summary['Start'] . '" /></td>
       </tr>
       <tr>
         <td align="right">' . $AppUI->_('End Date') . ':</td>
         <td><input type="text" name="project_end_date" value="' . $reader->proj->summary['Finish'] . '" /></td>
       </tr>
       <tr>
         <td colspan="2">' . $AppUI->_('Users') . ':</td>
       </tr>';
     // Users (Resources)
     $resources = array();
     $resources[0] = '';
     //check the existence of resources before trying to import
     if ($this->user_control) {
         $q = new DBQuery();
         $trabalhadores = $reader->proj->resources->children();
         foreach ($trabalhadores as $r) {
             $q->clear();
             $q->addQuery('user_id');
             $q->addTable('users');
             $q->leftJoin('contacts', 'c', 'user_contact = contact_id');
             $q->addWhere("user_username LIKE '{$r['name']}' OR CONCAT_WS(contact_first_name, ' ', contact_last_name) = '{$r['name']}'");
             $r['LID'] = $q->loadResult();
             if (!empty($r['name'])) {
                 $output .= '
               <tr>
                 <td>' . $AppUI->_('User name') . ': </td>
                 <td>
                     <input type="text" name="users[' . $r['uid'] . '][user_username]" value="' . ucwords(strtolower($r['name'])) . '"' . (empty($r['LID']) ? '' : ' readonly') . ' />
                     <input type="hidden" name="users[' . $r['uid'] . '][user_id]" value="' . $r['LID'] . '" />
                     (' . $AppUI->_('Resource UID') . ": " . $r['uid'] . ')';
                 if (function_exists('w2PUTF8strlen')) {
                     if (w2PUTF8strlen($r['name']) < w2PgetConfig('username_min_len')) {
                         $output .= ' <em>' . $AppUI->_('username_min_len.') . '</em>';
                     }
                 } else {
                     if (strlen($r['name']) < w2PgetConfig('username_min_len')) {
                         $output .= ' <em>' . $AppUI->_('username_min_len.') . '</em>';
                     }
                 }
                 $output .= '</td></tr>';
                 $resources[sizeof($resources)] = strtolower($r['name']);
             }
         }
     }
     // Insert Tasks
     $output .= '
   <tr>
     <td colspan="2">' . $AppUI->_('Tasks') . ':</td>
   </tr>
   <tr>
     <td colspan="2">
     <table width="100%">
     <tr>
         <th></th>
         <th>' . $AppUI->_('Name') . '</th>
         <th>' . $AppUI->_('Start Date') . '</th>
         <th>' . $AppUI->_('End Date') . '</th>
         <th>' . $AppUI->_('user allocations') . '</th>
     </tr>';
     foreach ($reader->proj->tasks->children() as $task) {
         if ($task['ID'] != 0 && trim($task['Name']) != '') {
             $newWBS = $this->montar_wbs($task['OutlineLevel']);
             $note = " ";
             $output .= '<tr><td>';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][UID]" value="' . $task['ID'] . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][OUTLINENUMBER]" value="' . $newWBS . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_name]" value="' . $task['Name'] . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_description]" value="' . $note . '" />';
             $priority = 0;
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_priority]" value="' . $priority . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_start_date]" value="' . $task['Start'] . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_end_date]" value="' . $task['Finish'] . '" />';
             $myDuration = $this->dur($task['Duration']);
             $percentComplete = isset($task['PercentComplete']) ? $task['PercentComplete'] : 0;
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_duration]" value="' . $myDuration . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_percent_complete]" value="' . $percentComplete . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_description]" value="' . $note . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_owner]" value="' . $AppUI->user_id . '" />';
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_type]" value="0" />';
             $milestone = $task['Milestone'] == 'yes' ? 1 : 0;
             $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][task_milestone]" value="' . $milestone . '" />';
             $temp = 0;
             if (!empty($task['UniqueIDPredecessors'])) {
                 $x = strpos($task['UniqueIDPredecessors'], ",");
                 foreach ($task['UniqueIDPredecessors'] as $dependency) {
                     $output .= '<input type="hidden" name="tasks[' . $task['ID'] . '][dependencies][]" value="' . $dependency['UniqueIDPredecessors'] . '" />';
                     //'.$task['ID'].'-'.$temp.'
                     ++$temp;
                 }
             }
             $output .= '</td><td>';
             for ($i = 1; $i < $task['OutlineLevel']; $i++) {
                 $output .= w2PshowImage(w2PfindImage('corner-dots.gif')) . '&nbsp;';
             }
             $output .= $task['Name'] . '<br /><hr />' . $task['NOTES'] . '<hr size="2" /></td><td>' . $task['Start'] . '</td><td>' . $task['Finish'] . '</td><td>';
             $recurso = '';
             $perc = 100;
             //This is a bizarre function i've made to associate the resources with their tasks
             //If there's only one resource associate to a task, it skip the while. If there's more than one
             //the loop take care of it until the last resource
             //strange but it works, that's my moto.
             if (!empty($task['Resources'])) {
                 $x = 0;
                 $y = strpos($task['Resources'], ';');
                 while (!empty($y)) {
                     $recurso = substr($task['Resources'], $x, $y - $x);
                     $output .= arraySelect($resources, 'tasks[' . $task['ID'] . '][resources][]', '', $recurso);
                     $output .= '<input type="text" name=tasks[' . $task['ID'] . '][resources_alloc][]" value="' . sprintf("%.0f", $perc) . '" size="3" />%<br />';
                     $x = $y + 1;
                     $y = strpos($task['Resources'], ';', $x);
                 }
                 $recurso = substr($task['Resources'], $x);
                 $output .= arraySelect($resources, 'tasks[' . $task['ID'] . '][resources][]', '', $recurso);
                 $output .= '<input type="text" name=tasks[' . $task['ID'] . '][resources_alloc][]" value="' . sprintf("%.0f", $perc) . '" size="3" />%<br />';
             }
             $output .= '</td></tr>';
         }
     }
     $output .= '</table></td></tr>';
     $output .= '</table>';
     return $output;
 }