File size: 4,964 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php

class EnterpriseClass extends PMPlugin
{
    public function __construct()
    {
        set_include_path(PATH_CORE . 'methods' . PATH_SEP . 'enterprise' . PATH_SEPARATOR . get_include_path());
    }

    public function getFieldsForPageSetup()
    {
        return array();
    }

    //update fields
    public function updateFieldsForPageSetup($oData)
    {
        return array();
    }

    public function setup()
    {
    }

    public function enterpriseSystemUpdate($data) //$data = $oData
    {
        if (count(glob(PATH_DATA_SITE . 'license/*.dat')) == 0) {
            return;
        }
        require_once ("classes/model/Users.php");
        $user = $data;
        $criteria = new Criteria("workflow");

        //SELECT
        $criteria->addSelectColumn(UsersPeer::USR_UID);
        //FROM
        //WHERE
        $criteria->add(UsersPeer::USR_USERNAME, $user->lName); //$user->lPassword
        $criteria->add(UsersPeer::USR_ROLE, "PROCESSMAKER_ADMIN");

        //query
        $rsSQLUSR = UsersPeer::doSelectRS($criteria);
        $rsSQLUSR->setFetchmode(ResultSet::FETCHMODE_ASSOC);

        $sw = 0;

        if (UsersPeer::doCount($criteria) > 0) {
            //if ($rsSQLUSR->getRecordCount() > 0) {
            $sw = 1;
        }

        /*
        $cnn = Propel::getConnection("workflow");
        $stmt = $cnn->createStatement();

        $sql = "SELECT USR.USR_UID
                FROM   USERS AS USR
                WHERE  USR.USR_USERNAME = '" . $user->lName . "' AND USR.USR_ROLE = 'PROCESSMAKER_ADMIN'";
        $rsSQLUSR = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);

        $sw = 0;

        if ($rsSQLUSR->getRecordCount() > 0) {
            $sw = 1;
        }
        */

        if ($sw == 1) {
            //Upgrade available
            $swUpgrade = 0;

            $addonList = AddonsStore::addonList();
            $addon = $addonList["addons"];

            if (count($addon) > 0) {
                $status = array("ready", "upgrade", "available");
                $pmVersion = EnterpriseUtils::pmVersion(PM_VERSION);

                foreach ($addon as $index => $value) {
                    if ($addon[$index]["id"] == "processmaker") {
                        if (version_compare($pmVersion . "", (EnterpriseUtils::pmVersion($addon[$index]["version"])) . "", "<")) {
                            $swUpgrade = 1;
                            break;
                        }
                    } else {
                        if (in_array($addon[$index]["status"], $status)) {
                            $swUpgrade = 1;
                            break;
                        }
                    }
                }
            }

            if ($swUpgrade == 1) {
                $_SESSION["__ENTERPRISE_SYSTEM_UPDATE__"] = 1;
            }
        }
    }

    public function enterpriseLimitCreateUser()
    {
        $oServerConf = &ServerConf::getSingleton();
        $infoLicense =$oServerConf->getProperty('LICENSE_INFO');
        if (isset($infoLicense[config("system.workspace")]['LIMIT_USERS'])) {
            $criteria = new Criteria('workflow');
            $criteria->add(UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL);
            $count = UsersPeer::doCount($criteria);
            if ($count >= $infoLicense[config("system.workspace")]['LIMIT_USERS'] ) {
                throw new Exception("You can\'t add more users to the System, this reach the limit of allowed users by license that it has installed now");
            }
        }
    }

    public function setHashPassword ($object)
    {
        $type = array('md5', 'sha256');
        if (!in_array($object->hash, $type)) {
            throw new Exception( 'Type: ' . $object->hash. ' No valid.');
            return false;
        }

        $config = new Configurations();
        $typeEncrypt = $config->getConfiguration('ENTERPRISE_SETTING_ENCRYPT', '');
        if ($typeEncrypt == null) {
            $typeEncrypt = array('current' => $object->hash, 'previous' => 'md5');
        } else {
            $typeEncrypt['previous'] = $typeEncrypt['current'];
            $typeEncrypt['current'] = $object->hash;
        }
        if ($object->hash != $typeEncrypt['previous']) {
            $config->aConfig = $typeEncrypt;
            $config->saveConfig('ENTERPRISE_SETTING_ENCRYPT', '');
        }

        $userProperty = new UsersProperties();

        $criteria = new Criteria($object->workspace->dbInfo['DB_RBAC_NAME']);
        $criteria->add(RbacUsersPeer::USR_STATUS, 0, Criteria::NOT_EQUAL);
        $dataset = RbacUsersPeer::doSelectRS($criteria);
        $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
        
        while ($dataset->next()) {
            $row = $dataset->getRow();
            $property = $userProperty->loadOrCreateIfNotExists($row['USR_UID'], array());
            $property['USR_LOGGED_NEXT_TIME'] = 1;
            $userProperty->update($property);
        }
    }
}