<?php

/****************************************************************************************************
    *	cronUserNotification.php
    *	Class for execute the cron of "UserNotification"
    *
    *	Created by Ronald Nina
    *	ronald.nina@processmaker.com
****************************************************************************************************/

class cronSendNotificationClassCron
{
    public function executeCron()
    {
        try {
            G::loadClass('pmFunctions');

            if (SYS_SYS == 'workflow' || SYS_SYS == 'fassil') {
                require_once PATH_PLUGINS . 'psFassilManagement/classes/class.cronSendNotification.php';
                $initTime = date('Y-m-d H:i:s');
                $pathCron = PATH_CORE . 'bin' . PATH_SEP . 'plugins' . PATH_SEP . 'cronSendNotification.php';
                echo "\n";
                eprintln("--- Initiating cron 'Task 5 Fassil' " . $initTime, 'green');

                $sqlScontrol = "SELECT *
                            FROM PLUGINS_REGISTRY
                            WHERE PLUGIN_CLASS_NAME = 'psFassilManagementPlugin'
                            ";
                $resScontrol = executeQuery($sqlScontrol);
                $resScontrol = array_shift($resScontrol);
                if ($resScontrol['PLUGIN_ENABLE'] == 1) {
                    $cCronSendNotification = new cronSendNotification();
                    $cCronSendNotification->searchCases();
                    // g::pr($this->searchSificonParameter('Url'));

                    $endTime = date('Y-m-d H:i:s');
                    eprintln('--- The cron file: ' . $pathCron . ' has been executed succesfully ' . $endTime, 'green');
                } else {
                    eprintln('--- The plugin psFassilManagementPlugin is disabled', 'red');
                }
            }
        } catch (Exception $e) {
            return $e->getMessage();
        }
    }

    public function searchSificonParameter($key)
    {
        $sQselectSSP = "SELECT *
                        FROM PMT_SOL_SIFICON_PARAMETERS
                        WHERE SSP_KEY='$key'";
        $sSelectSSP = executeQuery($sQselectSSP);
        $return = '';
        if (count($sSelectSSP) > 0) {
            $sSelectSSP = array_shift($sSelectSSP);
            $return = $sSelectSSP['SSP_VALUE'];
        }
        return $return;
    }
}

// $cronSendNotification = new cronSendNotificationClassCron();
// $cronSendNotification->executeCron();
