Example #1
0
 /**
  * Get monthly used space evolution chart
  * @return String
  */
 private static function loadHistoMonthlyUsedSpaceChart()
 {
     $units = array('', 'KB', 'MB', 'GB', 'TB');
     $u = OC_DLStCharts::getUConfValue('hu_size_hus', array('uc_val' => 3));
     $u = $units[$u['uc_val']];
     return 'histous=new Highcharts.Chart({chart:{renderTo:\'histo_us\',backgroundColor:\'#F8F8F8\',plotBackgroundColor:\'#F8F8F8\',type:\'column\'},title:{text:\'\'},xAxis:{categories:["' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 11)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 11)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 10)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 10)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 9)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 9)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 8)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 8)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 7)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 7)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 6)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 6)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 5)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 5)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 4)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 4)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 3)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 3)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 2)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 2)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m') - 1)))) . ' ' . date('Y', mktime(0, 0, 0, date('m') - 1)) . '","' . self::$l->t(ucfirst(date('F', mktime(0, 0, 0, date('m'))))) . ' ' . date('Y', mktime(0, 0, 0, date('m'))) . '"]},yAxis:{min:0,title:{text:\'' . self::$l->t('Average used space') . ' (' . $u . ')\'},stackLabels:{enabled:true,style:{fontWeight:\'bold\',color:(Highcharts.theme&&Highcharts.theme.textColor)||\'gray\'},formatter:function() {return(Math.round(this.total*100)/100);}}},legend:{align:\'center\',x:-20,verticalAlign:\'top\',y:20,floating:true,backgroundColor:(Highcharts.theme&&Highcharts.theme.legendBackgroundColorSolid)||\'white\',borderColor:\'#CCC\',borderWidth:1,shadow:false},tooltip:{formatter:function() {return \'<b>\'+this.x+\'</b><br/>\'+this.series.name+\': \'+(Math.round(this.y*100)/100)+\' ' . $u . '<br/>\'+\'Total: \'+(Math.round(this.point.stackTotal*100)/100)+\' ' . $u . '\';}},plotOptions:{column:{stacking:\'normal\',dataLabels:{enabled:false,color:(Highcharts.theme&&Highcharts.theme.dataLabelsColor)||\'white\'}}},series:[' . OC_DLStCharts::arrayParser('histo', OC_DLStCharts::getUsedSpaceOverTime('monthly'), self::$l, ',', 'hu_size_hus') . '],exporting:{enabled:false}});';
 }
Example #2
0
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check if we are a user
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('storagecharts2');
$tmpl = new OCP\Template('storagecharts2', 'tpl.settings');
if (isset($_POST['storagecharts2_disp']) && count($_POST['storagecharts2_disp']) <= 3) {
    $c = $_POST['storagecharts2_disp'];
    $c_disp = array('cpie_rfsus' => 0, 'clines_usse' => 0, 'chisto_us' => 0);
    foreach (array_keys($c_disp) as $chart) {
        if (in_array($chart, $c)) {
            $c_disp[$chart] = 1;
        }
    }
    OC_DLStCharts::setUConfValue('c_disp', serialize($c_disp));
    $tmpl->assign('stc_save_ok', TRUE);
}
$displays = OC_DLStCharts::getUConfValue('c_disp', array('uc_val' => 'a:3:{s:10:"cpie_rfsus";i:1;s:11:"clines_usse";i:1;s:9:"chisto_us";i:1;}'));
$tmpl->assign('displays', unserialize($displays['uc_val']));
// workaround to detect OC version
$ocVersion = @reset(OCP\Util::getVersion());
$tmpl->assign('ocVersion', $ocVersion);
return $tmpl->fetchPage();
Example #3
0
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either 
* version 3 of the License, or any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*  
* You should have received a copy of the GNU Lesser General Public 
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
* 
*/
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('storagecharts2');
$l = new OC_L10N('storagecharts2');
// Update and save the new configuration
if (is_numeric($_POST['s']) && in_array($_POST['k'], array('hu_size', 'hu_size_hus', 'hu_ratio'))) {
    OC_DLStCharts::setUConfValue($_POST['k'], $_POST['s']);
    switch ($_POST['k']) {
        case 'hu_size':
            OCP\JSON::encodedPrint(array('r' => OC_DLStChartsLoader::loadChart('chisto_us', $l)));
            break;
        case 'hu_size_hus':
            OCP\JSON::encodedPrint(array('r' => OC_DLStChartsLoader::loadChart('clines_usse', $l)));
            break;
    }
} else {
    // default
    OCP\JSON::encodedPrint(array('r' => OC_DLStChartsLoader::loadChart('cpie_rfsus', $l)));
}
Example #4
0
 *
 */
OCP\App::checkAppEnabled('storagecharts2');
$l = new OC_L10N('storagecharts2');
OC::$CLASSPATH['OC_DLStCharts'] = OC_App::getAppPath('storagecharts2') . "/lib/db.class.php";
OC::$CLASSPATH['OC_DLStChartsLoader'] = OC_App::getAppPath('storagecharts2') . "/lib/loader.class.php";
OCP\App::addNavigationEntry(array('id' => 'storagecharts2_index', 'order' => 60, 'href' => OCP\Util::linkTo('storagecharts2', 'index.php'), 'icon' => OCP\Util::imagePath('storagecharts2', 'app.svg'), 'name' => $l->t('Usage')));
OCP\App::registerPersonal('storagecharts2', 'settings');
// Get storage value for logged in user
$data_dir = OCP\Config::getSystemValue('datadirectory', '');
if (OCP\User::getUser() && strlen($data_dir) != 0) {
    $fs = OCP\Files::getStorage('files');
    // workaround to detect OC version
    $ocVersion = @reset(OCP\Util::getVersion());
    // OC 5
    if ($ocVersion < 6) {
        OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud 5', OCP\Util::DEBUG);
        $used = OC_DLStCharts::getTotalDataSize(OC::$CONFIG_DATADIRECTORY);
        // OC 6 or greater
    } else {
        $datadir = OC_Config::getValue('datadirectory') . '/' . OCP\User::getUser();
        OCP\Util::writeLog('storagecharts2', 'Running on OwnCloud ' . $ocVersion, OCP\Util::DEBUG);
        $used = OC_DLStCharts::getTotalDataSize($datadir);
    }
    // omit errors in desktop client ...
    if (method_exists($fs, 'free_space')) {
        OCP\Util::writeLog('storagecharts2', 'Calculating available space in oc << 8 for client', OCP\Util::DEBUG);
        $total = OC_DLStCharts::getTotalDataSize($data_dir) + $fs->free_space();
        OC_DLStCharts::update($used, $total);
    }
}
Example #5
0
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either 
* version 3 of the License, or any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*  
* You should have received a copy of the GNU Lesser General Public 
* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
* 
*/
OCP\JSON::checkLoggedIn();
if (in_array($_POST['k'], array('hu_size', 'sc_sort', 'hu_size_hus'))) {
    switch ($_POST['o']) {
        case 'set':
            $i = NULL;
            if (is_array($_POST['i'])) {
                $i = serialize($_POST['i']);
            } elseif (is_numeric($_POST['i'])) {
                $i = $_POST['i'];
            }
            OC_DLStCharts::setUConfValue($_POST['k'], $i);
            break;
        case 'get':
            $v = OC_DLStCharts::getUConfValue($_POST['k']);
            OCP\JSON::encodedPrint(array('r' => $v['uc_val']));
            break;
    }
}
Example #6
0
 /**
  * Parse an array and return data in the highCharts format
  *
  * @param $operation operation
  *            to do
  * @param $elements elements
  *            to parse
  */
 public static function arrayParser($operation, $elements, $l, $data_sep = ',', $ck = 'hu_size')
 {
     $return = "";
     switch ($operation) {
         case 'pie':
             $free = $total = 0;
             foreach ($elements as $element) {
                 $element = $element[0];
                 $total = $element['stc_total'];
                 $free += $element['stc_used'];
                 $return .= "['" . $element['oc_uid'] . "', " . $element['stc_used'] . "],";
             }
             $return .= "['" . $l->t('Free space') . "', " . ($total - $free) . "]";
             break;
         case 'histo':
         case 'line':
             $conf = OC_DLStCharts::getUConfValue($ck, array('uc_val' => 3));
             $div = 1;
             switch ($conf['uc_val']) {
                 case 4:
                     $div = 1024;
                 case 3:
                     $div *= 1024;
                 case 2:
                     $div *= 1024;
                 case 1:
                     $div *= 1024;
             }
             foreach ($elements as $user => $data) {
                 $return_tmp = '{"name":"' . $user . '","displayName":"' . OCP\User::getDisplayName($user) . '","data":[';
                 foreach ($data as $number) {
                     $return_tmp .= round($number / $div, 2) . ",";
                 }
                 $return_tmp = substr($return_tmp, 0, -1) . "]}";
                 $return .= $return_tmp . $data_sep;
             }
             $return = substr($return, 0, -strlen($data_sep));
             break;
     }
     return $return;
 }
Example #7
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check if we are a user
OCP\User::checkLoggedIn();
OCP\App::checkAppEnabled('storagecharts2');
OCP\Util::addStyle('storagecharts2', 'styles');
OCP\Util::addScript('storagecharts2', 'highcharts.min');
OCP\Util::addScript('storagecharts2', 'chosen.jquery.min');
OCP\Util::addScript('storagecharts2', 'chosen.proto.min');
OCP\Util::addScript('storagecharts2', 'storagecharts2');
$tmpl = new OCP\Template('storagecharts2', 'tpl.charts', 'user');
// Get data for all users if admin or just for the current user
$displays = OC_DLStCharts::getUConfValue('c_disp', array('uc_val' => 'a:3:{s:10:"cpie_rfsus";i:1;s:11:"clines_usse";i:1;s:9:"chisto_us";i:1;}'));
$displays = unserialize($displays['uc_val']);
$tmpl->assign('c_disp', $displays);
$sc_sort = OC_DLStCharts::getUConfValue('sc_sort', array('uc_val' => 'a:3:{i:0;s:10:"cpie_rfsus";i:1;s:11:"clines_usse";i:2;s:9:"chisto_us";}'));
$tmpl->assign('sc_sort', unserialize($sc_sort['uc_val']));
if ($displays['clines_usse']) {
    $hu_size = OC_DLStCharts::getUConfValue('hu_size', array('uc_val' => 3));
    $tmpl->assign('hu_size', $hu_size['uc_val']);
}
if ($displays['chisto_us']) {
    $hu_size_hus = OC_DLStCharts::getUConfValue('hu_size_hus', array('uc_val' => 3));
    $tmpl->assign('hu_size_hus', $hu_size_hus['uc_val']);
}
$tmpl->printPage();