function run($argc, $argv)
{
    global $debug;
    session_start();
    require_once '../civicrm.config.php';
    require_once 'api/v2/Domain.php';
    require_once 'api/v2/Group.php';
    require_once 'api/v2/GroupNesting.php';
    require_once 'api/v2/GroupOrganization.php';
    require_once 'api/v2/Contact.php';
    if ($argc < 3 || $argc > 4) {
        #var_dump($argv);
        print_usage($argv[0]);
        exit(-1);
    }
    $org_name = $argv[1];
    $org_desc = $argv[2];
    $config = CRM_Core_Config::singleton();
    //load bootstrap to call hooks
    require_once 'CRM/Utils/System.php';
    CRM_Utils_System::loadBootStrap();
    # create the domain
    $existing_domain = civicrm_domain_get();
    $domain_params = array('name' => $org_name, 'description' => $org_desc, 'version' => $existing_domain['version']);
    $domain = civicrm_domain_create($domain_params);
    if ($debug) {
        print "Create domain result: " . var_export($domain) . "\n";
    }
    $domain_id = $domain['id'];
    # find the parent group, if necessary
    if (!is_null($argv[3])) {
        $parent_group_name = $argv[3];
        $parent_group_params = array('title' => $parent_group_name);
        $parent_groups = civicrm_group_get($parent_group_params);
        if ($debug) {
            print "Find parent group result: " . var_export($parent_groups) . "\n";
        }
        $parent_group_keys = array_keys($parent_groups);
        $parent_group_id = $parent_group_keys[0];
    }
    # create the group
    $group_params = array('title' => $org_name, 'description' => $org_desc, 'is_active' => 1);
    $group = civicrm_group_add($group_params);
    if ($debug) {
        print "Create group result: " . var_export($group) . "\n";
    }
    $group_id = $group['result'];
    # create the org nesting if necessary
    if (!is_null($parent_group_id)) {
        $group_nesting_params = array('parent_group_id' => $parent_group_id, 'child_group_id' => $group_id);
        $group_nesting = civicrm_group_nesting_create($group_nesting_params);
        if ($debug) {
            print "Create group nesting result: " . var_export($group_nesting) . "\n";
        }
    }
    # create the org contact
    $org_params = array('organization_name' => $org_name, 'contact_type' => 'Organization');
    $org = civicrm_contact_create($org_params);
    if ($debug) {
        print "Create org contact result: " . var_export($org) . "\n";
    }
    $org_id = $org['contact_id'];
    # associate the two
    $group_org_params = array('group_id' => $group_id, 'organization_id' => $org_id);
    $group_org_id = civicrm_group_organization_create($group_org_params);
    if ($debug) {
        print "Create group-org association result: " . var_export($group_org_id) . "\n";
    }
    print "\n";
    print "Add or modify the following lines in the appropriate ";
    print "civicrm.settings.php file for {$org_name}:\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ID', {$domain_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_GROUP_ID', {$group_id} );\n";
    print "\tdefine( 'CIVICRM_DOMAIN_ORG_ID', {$org_id} );\n";
    print "\n";
}
Example #2
0
$PROGNAME = basename($_SERVER["SCRIPT_NAME"]);
$VERSION = "0.1.0";
$shortopts = "";
#$shortopts .= "f:";  // Required value
#$shortopts .= "v::"; // Optional value
#$shortopts .= "abc"; // These options do not accept values
$longopts = array("debug", "version", "help");
$options = getopt($shortopts, $longopts);
if (array_key_exists("debug", $options)) {
    $DEBUG = 1;
}
if (array_key_exists("version", $options)) {
    print_version();
}
if (array_key_exists("help", $options)) {
    print_usage();
}
function print_version()
{
    global $PROGNAME;
    global $VERSION;
    print "{$PROGNAME}:  version {$VERSION}\n";
    exit;
}
function print_usage($message = "", $retval = 0)
{
    if ($message) {
        print "{$message}\n";
    }
    global $PROGNAME;
    print "Usage:  " . $PROGNAME . " [options] \n";
Example #3
0
    echo print_usage() . $searcher->getUsage();
    exit(1);
}
// Build query sets
$requests = array();
if (isset($options['q']) || isset($options['s']) && isset($options['u'])) {
    $requests[] = $searcher->buildAPIRequest($options);
} else {
    if (isset($options['f'])) {
        $queries = ThreatExchangeUtils::parseQueryFile($options['f']);
        foreach ($queries as $query) {
            $options['q'] = $query;
            $requests[] = $searcher->buildAPIRequest($options);
        }
    } else {
        echo print_usage() . $searcher->getUsage();
        exit(1);
    }
}
// make the requests via Curl
$results = array();
foreach ($requests as $request) {
    try {
        $raw_result = ThreatExchangeUtils::makeCurlRequest($request);
        $json = json_decode($raw_result, true, 512, JSON_BIGINT_AS_STRING);
        if (isset($json['data'])) {
            $results = array_merge($results, $json['data']);
        }
    } catch (Exception $e) {
        echo $e->getMessage() . "\n";
        exit(1);
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    elis
 * @subpackage curriculummanagement
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2008-2012 Remote Learner.net Inc http://www.remote-learner.net
 *
 */
require_once '../config.php';
require_once '../lib/cluster.class.php';
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('no web access');
}
if ($argc > 1) {
    die(print_usage());
}
mtrace("Begin cluster fixes...");
$clusters = cluster_get_listing('id', 'ASC', 0);
$clusters_fixed_cnt = 0;
foreach ($clusters as $clusid => $clusdata) {
    if ($clusdata->parent > 0) {
        $select = "id='{$clusdata->parent}'";
        $parent_cnt = $CURMAN->db->count_records_select(CLSTTABLE, $select);
        if ($parent_cnt < 1) {
            mtrace('Cluster ID:' . $clusid . ' Name:' . $clusdata->name . ' converted to top-level');
            $newclusdata = new stdClass();
            $newclusdata->id = $clusdata->id;
            $newclusdata->parent = 0;
            $newclusdata->depth = 1;
            // Update the records in crlm_cluster table
$from_time = array_shift($args);
if (empty($from_time)) {
    print_usage("ERROR: You need to enter the From Time as the third argument.");
}
$from_time = strtotime($from_time);
if ($from_time === FALSE) {
    print_usage("ERROR: Invalid From Time.");
}
// Get to time
$to_time = array_shift($args);
if (empty($to_time)) {
    print_usage("ERROR: You need to enter the To Time as the forth argument.");
}
$to_time = strtotime($to_time);
if ($to_time === FALSE) {
    print_usage("ERROR: Invalid To Time.");
}
// Get export file name
$export_file = array_shift($args);
// Create CSV log file
$form_edit_fns = $form->getEditFns();
$csv = $form_edit_fns->createCSVSubmissionLogs($form, $from_time, $to_time);
// If there is export file name specified, set it
if (!is_null($export_file)) {
    $csv->setFilepath($export_file);
}
// Print to screen or save to file
$csv->export(TRUE);
// Restore current user
$GLOBALS['SQ_SYSTEM']->restoreCurrentUser();
/*-------------------------------FUNCTIONS--------------------------------*/
Example #6
0
    define('__ROOT__', realpath(dirname(__FILE__)));
}
require_once __ROOT__ . '/ThreatExchangeConfig.php';
ThreatExchangeConfig::init();
// Get the command line options
$options = getopt('d:f:g:hm:p:t:');
if (!isset($options['t'])) {
    echo print_usage();
    exit(1);
}
// Load user details
$app_id = ThreatExchangeConfig::getAppID();
$app_secret = ThreatExchangeConfig::getAppSecret();
$uploader = BaseUpload::getUploader($options['t']);
if (!$uploader->hasValidOptions($options)) {
    echo print_usage() . $uploader->getUsage();
    exit(1);
}
// Build POST data sets
$entries = $uploader->parseDataFile($options['f'], $options);
// make the requests via Curl
$results = array();
foreach ($entries as $request_uri => $post_data) {
    try {
        echo "Calling {$request_uri} with " . implode(',', $post_data) . "\n";
        $raw_result = ThreatExchangeUtils::makeCurlPostRequest($uploader->buildAPIUploadRequest(), $post_data);
        $json = json_decode($raw_result, true, 512, JSON_BIGINT_AS_STRING);
        if (isset($json['data'])) {
            $results = array_merge($results, $json['data']);
        }
    } catch (Exception $e) {
Example #7
0
function main($argc, $argv)
{
    if ($argc == 1) {
        if (function_exists('target_default')) {
            target_default();
        } else {
            print_usage($argv[0], true);
        }
    }
    if ($argc > 1) {
        $target = 'target_' . $argv[1];
        if (function_exists($target)) {
            $target();
        } elseif ($argv[1] == '-h' || $argv[1] == '--help') {
            print_usage($argv[0]);
            $avail_targets = array();
            $funcs = get_defined_functions();
            foreach ($funcs['user'] as $func) {
                if ('target_' === substr($func, 0, 7)) {
                    $avail_targets[] = str_replace('target_', '', $func);
                }
            }
            printf("\n  %s\n\n", 'available targets:');
            foreach ($avail_targets as $option) {
                printf("    %s\n", $option);
            }
            printf("\n");
        } else {
            print_usage($argv[0], true);
        }
    }
}
Example #8
0
    print_usage('missing argument --ini');
}
if (!isset($arguments['infra']) || !$arguments['infra'] || is_null($arguments['infra'])) {
    print_usage('missing argument --infra');
}
if (!isset($arguments['partner_id']) || !$arguments['partner_id'] || is_null($arguments['partner_id'])) {
    print_usage('missing argument --partner_id');
}
if (!isset($arguments['admin_secret']) || !$arguments['admin_secret'] || is_null($arguments['admin_secret'])) {
    print_usage('missing argument --admin_secret');
}
if (!isset($arguments['host']) || !$arguments['host'] || is_null($arguments['host'])) {
    print_usage('missing argument --host');
}
if (!file_exists($arguments['ini'])) {
    print_usage('config file not found ' . $arguments['ini']);
}
error_reporting(0);
$confObj = init($arguments['ini'], $arguments['infra']);
$kclient = getClient($arguments['partner_id'], $arguments['admin_secret'], $arguments['host']);
$baseTag = $confObj->general->component->name;
$defaultTags = "autodeploy, {$baseTag}_{$confObj->general->component->version}";
$sections = explode(',', $confObj->general->component->required_widgets);
if ($includeCode) {
    $code[] = '$c = new Criteria();';
    $code[] = '$c->addAnd(UiConfPeer::PARTNER_ID, ' . $confObj->statics->partner_id . ');';
    $code[] = '$c->addAnd(UiConfPeer::TAGS, "%' . $baseTag . '_".$this->kmc_' . $baseTag . '_version."%", Criteria::LIKE);';
    $code[] = '$c->addAnd(UiConfPeer::TAGS, "%autodeploy%", Criteria::LIKE);';
    $code[] = '$this->confs = UiConfPeer::doSelect($c);';
}
$tags_search = array();
Example #9
0
    } elseif (strstr($arg, '--url')) {
        list(, $url) = explode('=', $arg);
    } elseif (strstr($arg, '--dir')) {
        list(, $dir) = explode('=', $arg);
    } elseif (strstr($arg, '--dsn')) {
        list(, $dsn) = explode('=', $arg);
        $syncml_backend_parms['dsn'] = $dsn;
        $syncml_backend_driver = 'Sql';
    } elseif (strstr($arg, '--debug')) {
        if (strstr($arg, '=') !== false) {
            list(, $debuglevel) = explode('=', $arg);
        } else {
            $debuglevel = 5;
        }
    } else {
        print_usage("Unrecognised option {$arg}");
    }
}
require_once 'Log.php';
require_once 'SyncML/Device.php';
require_once 'SyncML/Device/Sync4j.php';
require_once 'SyncML/Backend.php';
/* Do Horde includes if test for horde backend: */
if ($syncml_backend_driver == 'Horde') {
    require_once __DIR__ . '/../../../lib/Application.php';
    Horde_Registry::appInit('horde', array('cli' => true, 'session_control' => 'none'));
}
if (!empty($testsetuponly)) {
    $testbackend = Horde_SyncMl_Backend::factory($syncml_backend_driver, $syncml_backend_parms);
    $testbackend->testSetup(SYNCMLTEST_USERNAME, 'syncmltest');
    echo "Test setup for user syncmltest done. Now you can start to record a test case.\n";
Example #10
0
/**
 * Parses the cli arguments.
 *
 * @return Boolean that indicates whether the given arguments are
 *         fine.
 */
function parse_arguments()
{
    global $argv;
    if (!isset($argv)) {
        if (false === (bool) ini_get('register_argc_argv')) {
            error_log('[ERROR] Please enable register_argc_argv in your php.ini.');
        } else {
            error_log('[ERROR] No $argv array available.');
        }
        echo PHP_EOL;
        return false;
    }
    // Remove the script name (first argument)
    global $scriptname;
    $scriptname = array_shift($argv);
    if (count($argv) === 0) {
        error_log('[ERROR] Missing argument.');
        return false;
    }
    // Set the path and remove from command line (last argument)
    global $path;
    $path = (string) array_pop($argv);
    // Parse options
    $longopts = ["help", "version", "format:", "nodes:", "relationships:"];
    $options = getopt("hvf:n:r:", $longopts);
    if ($options === FALSE) {
        error_log('[ERROR] Could not parse command line arguments.');
        return false;
    }
    // Help?
    if (isset($options['help']) || isset($options['h'])) {
        print_version();
        echo PHP_EOL;
        print_usage();
        echo PHP_EOL;
        print_help();
        exit(0);
    }
    // Version?
    if (isset($options['version']) || isset($options['v'])) {
        print_version();
        exit(0);
    }
    // Format?
    if (isset($options['format']) || isset($options['f'])) {
        global $format;
        switch ($options['format'] ?? $options['f']) {
            case "jexp":
                $format = CSVExporter::JEXP_FORMAT;
                break;
            case "neo4j":
                $format = CSVExporter::NEO4J_FORMAT;
                break;
            default:
                error_log("[WARNING] Unknown format '{$options['f']}', using neo4j format.");
                $format = CSVExporter::NEO4J_FORMAT;
                break;
        }
    }
    // Nodes file?
    if (isset($options['nodes']) || isset($options['n'])) {
        global $nodefile;
        $nodefile = $options['nodes'] ?? $options['n'];
    }
    // Relationships file?
    if (isset($options['relationships']) || isset($options['r'])) {
        global $relfile;
        $relfile = $options['relationships'] ?? $options['r'];
    }
    return true;
}
Example #11
0
#! /usr/bin/env php
<?php 
include dirname(__FILE__) . '/../www/config.php';
if (count($argv) != 4) {
    print_usage();
}
$sdk = (double) $argv[2];
if ($sdk <= 0 || $sdk > 20) {
    print_usage("karma should be > 0 and < 20");
}
$mess = $db->escape($argv[3]);
if (empty($mess) || mb_strlen($mess) < 6) {
    print_usage("message is empty or too short");
}
$user = new User();
$user->username = $argv[1];
if (!$user->read()) {
    print_usage('User not found');
}
echo "karma: {$user->karma} ";
$user->add_karma(-$sdk, $mess);
$user->read();
echo "-> {$user->karma}\n";
function print_usage($mess = false)
{
    if ($mess) {
        echo "Error: {$mess}\n";
    }
    echo 'Usage: ' . basename(__FILE__) . ' username karma_to_discount message' . "\n";
    die;
}
Example #12
0
function parse_options()
{
    $opts = getopt("p::h");
    global $conn;
    if (isset($opts["p"])) {
        $conn->port = $opts["p"];
    }
    if (isset($opts["h"])) {
        print_usage();
        exit(0);
    }
}
    }
    $b = explode("=", $arg);
    if (isset($options[$b[0]])) {
        $options[$b[0]] = $b[1];
    } else {
        echo "Uknown option: {$b['0']}";
        exit;
    }
    //else
}
//foreach
if ($options['instances_file'] == 'instances/file/path/') {
    echo "** Please specify a valid instances file **" . PHP_EOL;
    exit;
}
$options = print_usage($argv, $argc);
$endpoints = makeEndpoints($options['instances_file']);
$lsr_arr = readLSRIntoArr($options['lsr_file']);
//search the lsr for the descriptions of the endpoints found in endpoints
$endpoints_desc = parseDescriptions($endpoints, $lsr_arr);
$endpoint_stats = retrieveStatistics($endpoints);
makeHTML($endpoint_stats, $endpoints_desc);
/***************/
/** FUNCTIONS **/
/***************/
function print_usage($argv, $argc)
{
    $options = array("instances_file" => "/instances/file/path/", "lsr_file" => "/path/to/lsr");
    // show command line options
    if ($argc == 1) {
        echo "Usage: php {$argv['0']} ";
Example #14
0
$options .= 'w:';
// working directory
$options .= 'l:';
// language
$options .= 'e:';
// source database engine
$options .= 'f:';
// source database file
$options .= 'g:';
// generator command
$options .= 's:';
// file suffix
$exit = 0;
$options = getopt($options);
if (count($options) == 0) {
    print_usage($options);
}
$options = array_merge($option_defaults, $options);
if (array_key_exists('v', $options)) {
    $verbose = true;
}
if (array_key_exists('h', $options)) {
    $html_table = true;
}
verbose("PromptGenerator is generating Asterisk(R) voice prompts from database.");
verbose("\t(c) Copyright 2009, AMOOMA GmbH - Distributed under the terms of the GNU General Public License\n");
if ($options['e'] == 'file' && ($options['f'] == '' || !file_exists($options['f']))) {
    print_error('Input file "' . $options['f'] . '" does not exist!');
    $exit = 1;
}
if ($options['w'] == '' || !is_dir($options['w'])) {
function main()
{
    global $argv;
    if (count($argv) > 1) {
        switch (strtolower($argv[1])) {
            case "generate":
                $ret = generate();
                break;
            case "index":
                $ret = index();
                break;
            case "search":
                $ret = search();
                break;
            case "daemon":
                $ret = daemon();
                break;
            case "merge":
                $ret = merge();
                break;
            default:
                $ret = false;
        }
        if ($ret) {
            return;
        }
    }
    print_usage();
}