<?php

require "login/login.php";
include 'monitor.inc';
include 'db_utils.inc';
$user_id = getCurrentUserId();
try {
    // Folder
    if (isset($_REQUEST['folderId'])) {
        $folderId = $_REQUEST['folderId'];
        $_SESSION['scriptsFolderId'] = $folderId;
    }
    if (!isset($_SESSION['scriptsFolderId'])) {
        $_SESSION['scriptsFolderId'] = getRootFolderForUser($user_id, 'WPTScript');
    }
    $folderId = $_SESSION['scriptsFolderId'];
    $smarty->assign('folderId', $_SESSION['scriptsFolderId']);
    $folderTree = getFolderTree($user_id, 'WPTScript');
    $smarty->assign('folderTree', $folderTree);
    // Handle scriptsFilter settings
    if (isset($_REQUEST['clearScriptsFilter'])) {
        unset($_SESSION['scriptsFilterField']);
        unset($_SESSION['scriptsFilterValue']);
    } else {
        if (isset($_REQUEST['scriptsFilterField']) && ($scriptsFilterField = $_REQUEST['scriptsFilterField'])) {
            $_SESSION['scriptsFilterField'] = $scriptsFilterField;
        }
        if (isset($_REQUEST['scriptsFilterValue']) && ($scriptsFilterValue = $_REQUEST['scriptsFilterValue'])) {
            $_SESSION['scriptsFilterValue'] = $scriptsFilterValue;
        }
    }
    } else {
        $_SESSION['showInactiveJobsGraph'] = false;
    }
} else {
    if (!isset($_SESSION['showInactiveJobsGraph'])) {
        $_SESSION['showInactiveJobsGraph'] = false;
    }
}
$showInactiveJobs = $_SESSION['showInactiveJobsGraph'];
$smarty->assign('showInactiveJobsGraph', $showInactiveJobs);
// Folder handling
if (isset($_REQUEST['folderId'])) {
    $_SESSION['jobsFolderId'] = $_REQUEST['folderId'];
}
if (!isset($_SESSION['jobsFolderId'])) {
    $_SESSION['jobsFolderId'] = getRootFolderForUser($userId, 'WPTJob');
}
$folderId = $_SESSION['jobsFolderId'];
$smarty->assign('folderId', $_SESSION['jobsFolderId']);
$folderTree = getFolderTree($userId, 'WPTJob');
$smarty->assign('folderTree', $folderTree);
// End Folder handling
if (!isset($_REQUEST['includeRepeatView'])) {
    $includeRepeatView = 0;
} else {
    $includeRepeatView = 1;
}
$smarty->assign('includeRepeatView', $includeRepeatView);
// Start/end times
// timeFrame > 0 will ignore time select boxes
$timeFrame = '';
    $_SESSION['changeNotesCurrentPage'] = 1;
}
$changeNotesCurrentPage = $_SESSION['changeNotesCurrentPage'];
if (isset($_REQUEST['showPublic']) && ($showPublic = $_REQUEST['showPublic'])) {
    $_SESSION['changeNoteShowPublic'] = $showPublic;
}
if (!isset($_SESSION['changeNoteShowPublic'])) {
    $_SESSION['changeNoteShowPublic'] = 'true';
}
$smarty->assign('showPublic', $_SESSION['changeNoteShowPublic']);
// Folder
if (isset($_REQUEST['folderId']) && ($folderId = $_REQUEST['folderId'])) {
    $_SESSION['changeNoteFolderId'] = $folderId;
}
if (!isset($_SESSION['changeNoteFolderId'])) {
    $_SESSION['changeNoteFolderId'] = getRootFolderForUser($user_id, 'ChangeNote');
}
$folderId = $_SESSION['changeNoteFolderId'];
$smarty->assign('folderId', $_SESSION['changeNoteFolderId']);
$folderTree = getFolderTree($user_id, 'ChangeNote');
$smarty->assign('folderTree', $folderTree);
try {
    $q = Doctrine_Query::create()->from('ChangeNote c, c.ChangeNoteFolder f')->groupBy('c.Id');
    if ($folderId > -1 && hasPermission('ChangeNote', $folderId, PERMISSION_READ)) {
        $q->andWhere('c.ChangeNoteFolderId = ?', $folderId);
    } else {
        $q->andWhere('c.UserId = ?', $user_id)->orWhere('c.Public = ?', true);
    }
    $pager = new Doctrine_Pager($q, $changeNotesCurrentPage, $resultsPerPage);
    $result = $pager->execute();
    //  $changeNoteTable = Doctrine_Core::getTable('ChangeNote');
require "login/login.php";
include 'monitor.inc';
$ownerId = "";
$userId = getCurrentUserId();
if (isset($_REQUEST['id'])) {
    $jobId = $_REQUEST['id'];
    $ownerId = getOwnerIdFor($jobId, 'WPTJob');
    $currentJobCount = getUserJobCount($userId);
    $maxJobsPerMonth = getMaxJobsPerMonth($userId);
    $folderId = getFolderIdFor($jobId, 'WPTJob');
} else {
    if (isset($_REQUEST['folderId'])) {
        $folderId = $_REQUEST['folderId'];
    } else {
        $folderId = getRootFolderForUser($userId, 'WPTJob');
    }
}
if (!hasPermission('WPTJob', $folderId, PERMISSION_UPDATE)) {
    echo "Invalid Permission";
    exit;
}
// Folder shares for the Alerts
$folderShares = getFolderShares($userId, 'Alert');
$alertFolderIds = array();
foreach ($folderShares as $key => $folderShare) {
    foreach ($folderShare as $k => $share) {
        $alertFolderIds[] = $k;
    }
}
// Scripts
<?php

require "login/login.php";
include 'monitor.inc';
global $tableNameLabel;
if (isset($_REQUEST['tableName'])) {
    $tableName = $_REQUEST['tableName'];
} else {
    $tableName = "WPTJob";
}
$tableLabel = $tableNameLabel[$tableName];
//$folder = $_REQUEST['folder'];
if (isset($_REQUEST['folderId'])) {
    $folderId = $_REQUEST['folderId'];
} else {
    $folderId = getRootFolderForUser(getCurrentUserId(), $tableName);
}
$folderTree = getFolderTree(getCurrentUserId(), $tableName);
$folderTable = Doctrine_Core::getTable($tableName . 'Folder');
$folder = $folderTable->find($folderId);
$smarty->assign('folderTree', $folderTree);
$smarty->assign('tableNameLabel', $tableLabel);
$smarty->assign('tableName', $tableName);
$smarty->assign('folderId', $folderId);
$smarty->assign('folderName', $folder['Label']);
//echo $tableName.'<br>'.$folderId;exit;
try {
    $userId = getCurrentUserId();
    $q = Doctrine_Query::create()->from('Share s')->where('s.UserId = ?', $userId)->andWhere('s.TheTableName =?', $tableName)->andWhere('s.TableItemId = ?', $folderId);
    $result = $q->execute();
    $q->free(true);
<?php

require "login/login.php";
include 'monitor.inc';
include 'db_utils.inc';
$user_id = getCurrentUserId();
try {
    // Folder
    if (isset($_REQUEST['folderId']) && ($folderId = $_REQUEST['folderId'])) {
        $_SESSION['alertFolderId'] = $folderId;
    }
    if (!isset($_SESSION['alertFolderId'])) {
        $_SESSION['alertFolderId'] = getRootFolderForUser($user_id, 'Alert');
    }
    $folderId = $_SESSION['alertFolderId'];
    $smarty->assign('folderId', $_SESSION['alertFolderId']);
    $folderTree = getFolderTree($user_id, 'Alert');
    $smarty->assign('folderTree', $folderTree);
    // Handle filter settings
    if (isset($_REQUEST['clearFilter'])) {
        unset($_SESSION['alertsFilterField']);
        unset($_SESSION['alertsFilterValue']);
    } else {
        if (isset($_REQUEST['filterField']) && ($alertsFilterField = $_REQUEST['filterField'])) {
            $_SESSION['alertsFilterField'] = $alertsFilterField;
        }
        if (isset($_REQUEST['filterValue']) && ($alertsFilterValue = $_REQUEST['filterValue'])) {
            $_SESSION['alertsFilterValue'] = $alertsFilterValue;
        }
    }
    if (isset($_SESSION['alertsFilterField'])) {