Example #1
0
    function body_content()
    {
        global $FANNIE_OP_DB;
        $dbc = FannieDB::get($FANNIE_OP_DB);
        $superQ = $dbc->prepare_statement("SELECT s.superID,super_name FROM superdepts as s\n            LEFT JOIN superDeptNames AS n ON s.superID=n.superID\n            GROUP BY s.superID,super_name\n            ORDER BY super_name");
        $superR = $dbc->exec_statement($superQ);
        $opts = "";
        $firstID = False;
        $firstName = "";
        while ($superW = $dbc->fetch_row($superR)) {
            $opts .= "<option value={$superW['0']}>{$superW['1']}</option>";
            if ($firstID === False) {
                $firstID = $superW[0];
                $firstName = $superW[1];
            }
        }
        if (empty($opts)) {
            $opts .= "<option></option>";
        }
        $firstEmail = '';
        if ($firstID !== false) {
            $model = new SuperDeptEmailsModel($dbc);
            $model->superID($firstID);
            $model->load();
            $firstEmail = $model->email_address();
        }
        $deptRange = $dbc->getRow('SELECT MIN(dept_no) AS min, MAX(dept_no) AS max FROM departments');
        ob_start();
        ?>
        <div id="alertarea"></div>
        <div id="superdeptdiv">
            <div class="form-group">
            <label class="control-label">Select super department</label>
            <select class="form-control" id="superselect" onchange="superSelected();">
            <?php 
        echo $opts;
        ?>
            <option value=-1>Create a new super department</option>
            </select>
            </div>
            <div id="namefield" class="form-group collapse">
            <label class="control-label">Name</label>
            <input type="text" id="newname" class="form-control" value="<?php 
        echo $firstName;
        ?>
" />
            </div>
            <div class="form-group <?php 
        echo $firstEmail === '' ? 'hidden' : 'shown';
        ?>
">
            <label class="control-label">Email Address(es)</label>
            <input class="form-control" type="text" id="sd_email" value="<?php 
        echo $firstEmail;
        ?>
" />
            </div>
        </div>
        <hr />
        <div class="row">
        <div id="deptdiv" class="form-group col-sm-4">
            <label class="control-label">Members</label>
            <select class="form-control" id="deptselect" multiple size=15>
            <?php 
        foreach ($this->depts_in_super($firstID) as $id => $name) {
            printf('<option value=%d>%d %s</option>', $id, $id, $name);
        }
        ?>
            </select>
        </div>
        <div class="col-sm-1">
            <!-- lazy alignment -->
            <br />
            <br />
            <p>
            <button class="btn btn-default" type="submit" value="<<" 
                onclick="addDepts(); return false;">&lt;&lt;</button>
            </p>
            <p>
            <button class="btn btn-default" type="submit" value=">>" 
                onclick="remDepts(); return false;">&gt;&gt;</button>
            </p>
        </div>
        <div class="form-group col-sm-4">
            <label class="control-label">Non-members</label>
            <select class="form-control" id="deptselect2" multiple size=15>
            <?php 
        foreach ($this->depts_not_in_super($firstID) as $id => $name) {
            printf('<option value=%d>%d %s</option>', $id, $id, $name);
        }
        ?>
            </select>
        </div>
        </div>
        <p>
            <button type="submit" value="Save" onclick="saveData(); return false;"
                class="btn btn-default">Save</button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <a class="btn btn-default"
            href="../../reports/DepartmentSettings/DeptSettingsReport.php?dept1=<?php 
        echo $deptRange['min'];
        ?>
&dept2=<?php 
        echo $deptRange['max'];
        ?>
&submit=by_dr">View All Departments' Primary Super Department</a>
        </p>
        <?php 
        $this->add_script('super.js');
        $this->addOnloadCommand("\$('#sd_email').keyup(function(e){ if (e.which==13) saveData(); });\n");
        return ob_get_clean();
    }
Example #2
0
 /**
   Get all email addresses associated with
   the given department
   @param $dept [int] department number
   @return [string] email address(es) or [boolean] false
 */
 public static function getAddresses($dept)
 {
     $conf = \FannieConfig::factory();
     $dbc = \FannieDB::getReadOnly($conf->get('OP_DB'));
     $query = 'SELECT superID from superdepts WHERE dept_ID=? GROUP BY superID';
     $prep = $dbc->prepare($query);
     $res = $dbc->execute($prep, array($dept));
     $emails = '';
     while ($row = $dbc->fetch_row($res)) {
         $model = new \SuperDeptEmailsModel($dbc);
         $model->superID($row['superID']);
         if (!$model->load()) {
             continue;
         }
         $addr = $model->emailAddress();
         if ($addr && !strstr($emails, $addr)) {
             if ($emails !== '') {
                 $emails .= ', ';
             }
             $emails .= $addr;
         }
     }
     return $emails === '' ? false : $emails;
 }