コード例 #1
0
/**
 * Check validity of user/password/entity
 * If test is ko, reason must be filled into $_SESSION["dol_loginmesg"]
 *
 * @param	string	$usertotest		Login
 * @param	string	$passwordtotest	Password
 * @param   int		$entitytotest   Number of instance (always 1 if module multicompany not enabled)
 * @return	string					Login if OK, '' if KO
 */
function check_user_password_dolibarr($usertotest, $passwordtotest, $entitytotest = 1)
{
    global $db, $conf, $langs;
    global $mc;
    dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=" . $usertotest);
    $login = '';
    if (!empty($usertotest)) {
        try {
            $host = substr($conf->couchdb->host, 7);
            $client = new couchClient('http://' . $usertotest . ':' . $passwordtotest . '@' . $host . ':' . $conf->couchdb->port . '/', $conf->couchdb->name, array("cookie_auth" => TRUE));
            $_SESSION['couchdb'] = $client->getSessionCookie();
        } catch (Exception $e) {
            print $e->getMessage();
            exit;
        }
        if (strlen($_SESSION['couchdb']) < 15) {
            sleep(1);
            $langs->load('main');
            $langs->load('errors');
            $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword");
        } else {
            $login = $usertotest;
        }
    }
    return $login;
}
コード例 #2
0
 public function testDatabaseExists()
 {
     $exist = $this->client->databaseExists();
     $this->assertTrue($exist, "testing against an existing database");
     $client = new couchClient($this->couch_server, "foofoofooidontexist");
     $this->assertFalse($client->databaseExists(), "testing against a non-existing database");
 }
コード例 #3
0
ファイル: talk2db.php プロジェクト: T-TEL/TelBel
function recordActionViewed($resourceID, $dbgroup)
{
    global $couchUrl;
    $resources = new couchClient($couchUrl, $dbgroup);
    $doc = $resources->getDoc($_GET['resid']);
    $doc->views = intval($doc->views) + 1;
    $resources->storeDoc($doc);
}
コード例 #4
0
 public static function Add($subscription){
   global $config;
   echo "adding subscription to system\n";
   var_dump($subscription);
   $couch = new couchClient($config->database->connectionString, $config->database->name);
   $response = $couch->updateDoc("updates", "subscription_request", $subscription, $subscription->_id);
   //todo: check response
   return $subscription;
 }
コード例 #5
0
ファイル: index.php プロジェクト: jpweber/system_status_api
function set_monitor_status($server, $status)
{
    $client = new couchClient('http://<hostname>:5984', 'watchcat_hosts');
    $opts = array("key" => $server);
    $pre_doc = $client->setQueryParameters($opts)->getView('wc_hosts', 'by_hostname');
    $doc = $client->getDoc($pre_doc->rows[0]->id);
    $doc->monitor_active = $status;
    try {
        $response = $client->storeDoc($doc);
    } catch (Exception $e) {
        echo "something weird happened: " . $e->getMessage() . "<BR>\n";
    }
    var_dump($response);
}
コード例 #6
0
ファイル: CouchDb.php プロジェクト: rajeshpillai/df-couchdb
 /**
  * {@inheritdoc}
  */
 public function getAccessList()
 {
     $resources = [];
     //        $refresh = $this->request->queryBool( 'refresh' );
     $name = Schema::RESOURCE_NAME . '/';
     $access = $this->getPermissions($name);
     if (!empty($access)) {
         $resources[] = $name;
         $resources[] = $name . '*';
     }
     $result = $this->dbConn->listDatabases();
     foreach ($result as $name) {
         if ('_' != substr($name, 0, 1)) {
             $name = Schema::RESOURCE_NAME . '/' . $name;
             $access = $this->getPermissions($name);
             if (!empty($access)) {
                 $resources[] = $name;
             }
         }
     }
     $name = Table::RESOURCE_NAME . '/';
     $access = $this->getPermissions($name);
     if (!empty($access)) {
         $resources[] = $name;
         $resources[] = $name . '*';
     }
     foreach ($result as $name) {
         if ('_' != substr($name, 0, 1)) {
             $name = Table::RESOURCE_NAME . '/' . $name;
             $access = $this->getPermissions($name);
             if (!empty($access)) {
                 $resources[] = $name;
             }
         }
     }
     return $resources;
 }
コード例 #7
0
<?php

require_once "./config.default.php";
# If there are any overrides include them now
if (!is_readable('./config.php')) {
    echo "<H2>WARNING: Configuration file config.php does not exist. Please\n         notify your system administrator.</H2>";
} else {
    include_once './config.php';
}
require_once 'lib/couch.php';
require_once 'lib/couchClient.php';
require_once 'lib/couchDocument.php';
// set a new connector to the CouchDB server
$client = new couchClient('http://' . $couchdb_server . ':' . $couchdb_port, $couchdb_database);
// view fetching, using the view option limit
try {
    #    $view = $client->limit(100)->asArray()->getView('cronview','by_host');
    $client->key(-1);
    $view = $client->limit(100)->asArray()->getView('cronview', 'by_job_duration');
} catch (Exception $e) {
    echo "ERROR while getting view contents: " . $e->getMessage() . "<BR>\n";
}
##############################################################
# Did we get any response for the key we were looking for
##############################################################
if (sizeof($view["rows"]) > 0) {
    print "<h2>Currently Running Jobs</h2><p>\n  <table cellspacing=1 class=tablesorter border=1>\n  <thead>\n  <tr><th>Start time</th><th>Has been running so far (secs)</th><th>Username</th><th>Hostname</th><th>Command</th></tr>\n  </thead>\n  <tbody>";
    foreach ($view["rows"] as $key => $row) {
        $job_time = time() - strtotime($row["value"]["time"]);
        print "<tr><td>" . $row["value"]["time"] . "</td>" . "<td align=center>" . $job_time . "</td>" . "<td>" . $row["value"]["username"] . "</td>" . "<td>" . $row["value"]["hostname"] . "</td>" . "<td>" . $row["value"]["command_line"] . "</td>" . "</tr>\n";
    }
コード例 #8
0
ファイル: master.inc.php プロジェクト: nrjacker4/crm-php
}

/*
 * Object $db
 */
if (! defined('NOREQUIREDB'))
{
    $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);

	if ($db->error)
	{
		dol_print_error($db,"host=".$conf->db->host.", port=".$conf->db->port.", user="******", databasename=".$conf->db->name.", ".$db->error);
		exit;
	}
	
	$couch = new couchClient($conf->Couchdb->host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name);
	$couch->setSessionCookie("AuthSession=" . $_COOKIE['AuthSession']);
}

// Now database connexion is known, so we can forget password
unset($dolibarr_main_db_pass); 	// We comment this because this constant is used in a lot of pages
unset($conf->db->pass);				// This is to avoid password to be shown in memory/swap dump

/*
 * Object $user
 */
//if (! defined('NOREQUIREUSER'))
//{
//	$user = new User($db);
//}
コード例 #9
0
ファイル: couchAdmin.php プロジェクト: ntulip/PHP-on-Couch
 /**
  * returns all users
  *
  * @param boolean $include_docs if set to true, users documents will also be included
  * @return array users array : each row is a stdObject with "id", "rev" and optionally "doc" properties
  */
 public function getAllUsers($include_docs = false)
 {
     $client = new couchClient($this->client->dsn(), $this->userdb, $this->client->options());
     if ($include_docs) {
         $client->include_docs(true);
     }
     return $client->startkey("org.couchdb.user:"******"org.couchdb.user;")->getAllDocs()->rows;
 }
コード例 #10
0
ファイル: cabinet.php プロジェクト: klawd-prime/stack
 /**
  * Delete a file
  *
  * @param File $file
  */
 public function deleteFile(File $file)
 {
     $this->client->deleteDoc($file->getDocument());
 }
コード例 #11
0
ファイル: couchdb.php プロジェクト: jemmy655/PHP-on-Couch
 function __construct()
 {
     $ci =& get_instance();
     $ci->config->load("couchdb");
     parent::__construct($ci->config->item("couch_dsn"), $ci->config->item("couch_database"));
 }
コード例 #12
0
ファイル: convert_societe.php プロジェクト: nrjacker4/crm-php
 * 	\file       htdocs/comm/serverprocess.php
 * 	\ingroup    commercial societe
 * 	\brief      load data to display
 */
require_once("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT . "/comm/prospect/class/prospect.class.php");
require_once(DOL_DOCUMENT_ROOT . "/core/class/html.formother.class.php");
$langs->load("companies");
$langs->load("customers");
$langs->load("suppliers");
$langs->load("commercial");
/* Array of database columns which should be read and sent back to DataTables. Use a space where
 * you want to insert a non-database field (for example a counter or static image)
 */

$couchdb = new couchClient($conf->couchdb->host.':'.$conf->couchdb->port.'/',$conf->couchdb->name);

if (empty($conf->global->SOCIETE_DISABLE_STATE)) {
    if($conf->categorie->enabled){
         $aColumns = array('', 'company', 'ville', 'departement', 'cp', 'datec', 'categorie', 'sale','siren','siret','ape','idprof4', 'fk_prospectlevel', 'fk_stcomm', 'etat', 'priv');
         $aColumnsSql = array('', 's.nom', 's.ville', 'd.nom', 's.cp', 's.datec', 'c.label', 'u.login','s.siren','s.siret','s.ape','s.idprof4','s.fk_prospectlevel', 'fk_stcomm', '', '');
    }
    else {
         $aColumns = array('', 'company', 'ville', 'departement', 'cp', 'datec', 'sale','siren','siret','ape','idprof4', 'fk_prospectlevel', 'fk_stcomm', 'etat', 'priv');
         $aColumnsSql = array('', 's.nom', 's.ville', 'd.nom', 's.cp', 's.datec', 'u.login','s.siren','s.siret','s.ape','s.idprof4','s.fk_prospectlevel', 'fk_stcomm', '', '');
    }
}
else {
    if($conf->categorie->enabled){
        $aColumns = array('', 'company', 'ville', 'cp', 'datec', 'categorie', 'sale','siren','siret','ape','idprof4', 'fk_prospectlevel', 'fk_stcomm', 'etat', 'priv');
        $aColumnsSql = array('', 's.nom', 's.ville', 's.cp', 's.datec', 'c.label', 'u.login','s.siren','s.siret','s.ape','s.idprof4','s.fk_prospectlevel', 'fk_stcomm', '', '');
コード例 #13
0
<?php
if(strtotime($config->timing->submission_cutoff) < time()){
  echo '{ "success": false, "error": { "message": "The submission period for the day has passed. The cutoff time is '.$config->timing->submission_cutoff.'" } }';
  exit(0);
}

// TODO: This is insecure. Handle should be pulled from session instead of request.
$points = empty($_REQUEST['points']) ? array() : $_REQUEST['points'];
$handle = preg_replace('/[^a-z0-9]/i',"",$_REQUEST['handle']);
$date = date("m-d-Y");

require_once("couch.php");

$couch = new couchClient($config->database->connectionString, $config->database->name);

$feed = new stdClass();
$feed->points = $points;
$feed->handle = $handle;
$feed->date = $date;
$feed->type = "points";
$feed->_id = "points_".$date."_".$handle;

try {
  $response = $couch->updateDoc("updates", "feed", $feed, $feed->_id);
  if( !empty($response) && $response == "ok" )
    echo '{ "success": true }';
  else
    echo '{ "success": false, "error": { "message": "The database server returned a non-successful result.", "details": '.json_encode($response).' } }';
} catch(Exception $e) {
  echo '{ "success": false, "error": { "message": "'.$e->getMessage().'", "code": "'.$e->getCode().'" } }';
  exit(0);
コード例 #14
0
ファイル: metrics.php プロジェクト: jpweber/system_status_api
<head>
     <link rel="stylesheet" href="bootstrap/css/bootstrap.css" type="text/css">
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="resources/js/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.4.3/morris.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap-tooltip.js"></script>
</head>

<?php 
require_once 'couchlib/couch.php';
require_once 'couchlib/couchClient.php';
require_once 'couchlib/couchDocument.php';
require_once 'date_functions.php';
// set a new connector to the CouchDB server server stats
$client = new couchClient('http://172.25.1.45:5984', 'watchcat_stats');
$server = $_GET['server'];
$status = json_decode(file_get_contents(trim("http://" . $server . ":4569/metrics")));
$health = json_decode(file_get_contents(trim("http://" . $server . ":4569/status")));
//get stats from couchdb for $server (name)
//but first create dates to go in our query
$date = new DateTime();
$startdate = create_startdate($date);
//echo $startdate."<br>";
$enddate = create_enddate($startdate, 24);
//echo $enddate."<br>";
try {
    $opts = array("startkey" => array($server, $startdate), "endkey" => array($server, $enddate), "limit" => 24, "descending" => true);
    $cat_stats = $client->setQueryParameters($opts)->getView('stats', 'by_server_date');
} catch (Exception $e) {
    echo "something weird happened: " . $e->getMessage() . "<BR>\n";
コード例 #15
0
ファイル: locum-covers.php プロジェクト: aadl/locum
 /**
  * Clear an erroneous cover image from the cache
  */
 public function clear_covercache($bnum)
 {
     //$db = MDB2::connect($this->dsn);
     //$db->query("UPDATE locum_bib_items SET cover_img = '' WHERE bnum = " . $bnum);
     $couch = new couchClient($this->couchserver, $this->couchdatabase);
     try {
         $doc = $couch->getDoc((string) $bnum);
     } catch (Exception $e) {
         return FALSE;
     }
     unset($doc->cover_img);
     $couch->storeDoc($doc);
 }
コード例 #16
0
ファイル: couchdb.php プロジェクト: aadl/locum
#!/usr/bin/php
<?php 
/**
 * @file
 *   Initialize the sphinx view.
 */
chdir('..');
require_once 'locum.php';
$locum = new locum();
$client = new couchClient($locum->couchserver, $locum->couchdatabase);
// Create the view.
try {
    $doc = $client->getDoc('_design/sphinx');
} catch (Exception $e) {
    if ($e->getCode() == 404) {
        // document doesn't exist. create a new one
        $doc = new stdClass();
        $doc->_id = '_design/sphinx';
    } else {
        var_dump($e);
        exit;
    }
}
$doc->views = new stdClass();
$doc->views->by_sphinxid = new stdClass();
$doc->views->by_sphinxid->map = "function(doc) { if (doc.bnum) { emit(doc.bnum, null); } }";
// Save view.
$client->storeDoc($doc);
コード例 #17
0
ファイル: etape2.php プロジェクト: nrjacker4/crm-php
		}
	}
	/*	 * *************************************************************************************
	 *
	 * Load couchdb views and documents
	 *
	 * ************************************************************************************* */
	if ($ok) {
		include_once($dolibarr_main_document_root . "/core/db/couchdb/lib/couchClient.php");

		//print '<input type="hidden" name="couchdb_user_root" value="' . $_POST['couchdb_user_root'] . '">';
		//print '<input type="hidden" name="couchdb_pass_root" value="' . $_POST['couchdb_pass_root'] . '">';

		try {
			$host = substr($conf->Couchdb->host, 7);
			$couchdb = new couchClient('http://' . $_POST['couchdb_user_root'] . ':' . $_POST['couchdb_pass_root'] . '@' . $host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name, array("cookie_auth" => false));

			$couchdb->getDatabaseInfos();

			$dir = "couchdb/json/";

			// Create views and documents
			$handle = @opendir($dir);   // Dir may not exists
			if (is_resource($handle)) {
				while (($file = readdir($handle)) !== false) {
					if (preg_match('/\.json$/i', $file)) {
						$fp = fopen($dir . $file, "r");
						if ($fp) {
							$json = fread($fp, filesize($dir . $file));
							$obj = json_decode($json);
							
コード例 #18
0
 function ajaxgetpostsAction()
 {
     $topicId = $this->_request->getParam('topic');
     if ($topicId) {
         $topicId = urldecode($topicId);
         $startKey = array($topicId, 0, 0);
         $endKey = array($topicId, '{}', '{}');
         $config = Zend_Registry::get('config');
         $postsClient = new couchClient($config->couchdb->uri . ":" . $config->couchdb->port, $config->couchdb->posts_users);
         $posts = $postsClient->reduce(FALSE)->startkey($startKey)->endkey($endKey)->stale("ok")->asArray()->getView('socialmediathread', 'posts-by-topic');
         $this->view->posts = $posts['rows'];
         $return_posts = array();
         foreach ($posts['rows'] as $post) {
             if (isset($post['value']['date'])) {
                 list($year, $month, $day, $hour, $minute, $second) = $post['value']['date'];
                 $month += 1;
                 $date = date("Y-m-d g:i:s a", mktime($hour, $minute, $second, $month, $day, $year));
                 $post['value']['date'] = $date;
             } else {
                 $date = "-";
                 $post['value']['date'] = $date;
             }
             array_push($return_posts, $post);
         }
         //save read record
         $irrModel = new InboxReadRecord();
         $row = $irrModel->createRow();
         $row->topic = $topicId;
         $row->consumer = $this->_currentUser->id;
         $row->save();
         $this->_helper->layout->disableLayout();
         $this->_helper->json($return_posts);
     }
 }
コード例 #19
0
ファイル: convert_menu.php プロジェクト: nrjacker4/crm-php
/**
 * 	\file       htdocs/comm/serverprocess.php
 * 	\ingroup    commercial societe
 * 	\brief      load data to display
 */
require_once("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");;
$langs->load("companies");
$langs->load("customers");
$langs->load("suppliers");
$langs->load("commercial");
/* Array of database columns which should be read and sent back to DataTables. Use a space where
 * you want to insert a non-database field (for example a counter or static image)
 */

$couchdb = new couchClient("http://"."Administrator:admin@".substr($conf->Couchdb->host, 7).':'.$conf->Couchdb->port.'/',$conf->Couchdb->name);


$flush=0;
if($flush)
{
    // reset old value
    $result = $couchdb->limit(50000)->getView('MenuTop','target_id');
    $i=0;
    
    if(count($result->rows)==0)
    {
        print "Effacement terminé";
        exit;
    }
    
コード例 #20
0
global $couchUrl;
$couchUrl = 'http://127.0.0.1:5984';
///error_reporting(E_ERROR);
include "lib/couch.php";
include "lib/couchClient.php";
include "lib/couchDocument.php";
if (isset($argv[2])) {
    //Display all available args
    //print_r($argv);
    $faci_ID = $argv[3];
    $status = $argv[2];
    $statusType = $argv[1];
    $carrentStatus = new stdClass();
    $carrentStatus->systemtime = date('Y-m-d H:i:s');
    $carrentStatus->status = $status;
    $system = new couchClient($couchUrl, "system");
    $doc = $system->getDoc($faci_ID);
    // get data from form and save it to couch
    $doc->kind = "Server_Status_Log";
    $doc->lastUpdate = date('y-m-d');
    if (!isset($doc->{$statusType})) {
        $doc->{$statusType} = array();
        array_push($doc->{$statusType}, $carrentStatus);
    } else {
        if ($doc->{$statusType} != null) {
            array_push($doc->{$statusType}, $carrentStatus);
        } else {
            $doc->{$statusType} = array();
            array_push($doc->{$statusType}, $carrentStatus);
        }
    }
コード例 #21
0
/**
 This script demonstrates the basics of storing and retrieving documents using PHP On Couch
 For this to work, you have to tell the database DSN (example : http://couch.server.com:5984/) and the name of a database that does not exist
*/
$couch_dsn = "http://localhost:5984/";
$couch_db = "example";
/**
* include the library
*/
require_once "../lib/couch.php";
require_once "../lib/couchClient.php";
require_once "../lib/couchDocument.php";
/**
* create the client
*/
$client = new couchClient($couch_dsn, $couch_db);
/**
* As usual we create the database
*
*
*/
echo "#### Creating database " . $client->getDatabaseUri() . ': $result = $client->createDatabase();' . "\n";
try {
    $result = $client->createDatabase();
} catch (Exception $e) {
    if ($e instanceof couchException) {
        echo "We issued the request, but couch server returned an error.\n";
        echo "We can have HTTP Status code returned by couchDB using \$e->getCode() : " . $e->getCode() . "\n";
        echo "We can have error message returned by couchDB using \$e->getMessage() : " . $e->getMessage() . "\n";
        echo "Finally, we can have CouchDB's complete response body using \$e->getBody() : " . print_r($e->getBody(), true) . "\n";
        echo "Are you sure that your CouchDB server is at {$couch_dsn}, and that database {$couch_db} does not exist ?\n";
コード例 #22
0
<?php

require_once('couch.php');

$couch = new couchClient($config->database->connectionString, $config->database->name);
$results = $couch->key(date("m-d-Y"))->getView("views","pointsByDate");


render_header();
if($results->total_rows == 0 || empty($results->rows)){
  include('views/no_points.php');
} else {
  $points = $results->rows;
  include('views/points.php');
}
render_footer();
コード例 #23
0
ファイル: header.php プロジェクト: jpweber/system_status_api
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="http://watchcat.bluetonecommunications.com">Watch Cat</a>
        </div>
        <div class="collapse navbar-collapse">
           <ul class="nav navbar-nav">
	        <li><a href="http://watchcat.bluetonecommunications.com/cpu_load.php">CPU Load</a></li>
	        <li><a href="http://watchcat.bluetonecommunications.com/alerts.php">Alerts</a></li>

        
          <?php 
require_once 'couchlib/couch.php';
require_once 'couchlib/couchClient.php';
require_once 'couchlib/couchDocument.php';
// set a new connector to the CouchDB server
$couch_client = new couchClient('http://172.25.1.45:5984', 'watchcat_hosts');
$hostnames = $couch_client->getView('wc_hosts', 'hostnames');
echo '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Servers<b class="caret"></b></a><ul class="dropdown-menu">';
foreach ($hostnames as $rows) {
    foreach ($rows as $host) {
        echo "<li><a href='metrics.php?server=" . $host->key . "'>" . $host->key . "</a></li>";
    }
}
?>
         
          </ul>
   
          <ul class="nav navbar-nav navbar-right">
          
          </ul>
        </div><!--/.nav-collapse -->
コード例 #24
0
<body>
<?php 
require_once "./config.default.php";
# If there are any overrides include them now
if (!is_readable('./config.php')) {
    echo "<H2>WARNING: Configuration file config.php does not exist. Please\n         notify your system administrator.</H2>";
} else {
    include_once './config.php';
}
require_once 'lib/couch.php';
require_once 'lib/couchClient.php';
require_once 'lib/couchDocument.php';
$couch_url = 'http://' . $couchdb_server . ':' . $couchdb_port;
$couch_url_full = $couch_url . "/" . $couchdb_database;
// set a new connector to the CouchDB server
$client = new couchClient($couch_url, $couchdb_database);
?>

<?php 
// view fetching, using the view option limit
try {
    if (isset($_GET['command'])) {
        $client->key($_GET['command']);
    }
    $view = $client->limit(100)->asArray()->getView('cronview', 'by_commandline');
} catch (Exception $e) {
    echo "ERROR while getting view contents: " . $e->getMessage() . "<BR>\n";
}
##############################################################
# Did we get any response for the key we were looking for
##############################################################
コード例 #25
0
ファイル: locum-client.php プロジェクト: aadl/locum
 public function get_bib_items($bnum_arr)
 {
     if (is_callable(array(__CLASS__ . '_hook', __FUNCTION__))) {
         eval('$hook = new ' . __CLASS__ . '_hook;');
         return $hook->{__FUNCTION__}($bnum_arr);
     }
     if (count($bnum_arr)) {
         $couch = new couchClient($this->couchserver, $this->couchdatabase);
         try {
             $doc = $couch->asArray()->include_docs(true)->keys($bnum_arr)->getAllDocs();
         } catch (Exception $e) {
             return FALSE;
         }
     }
     return $doc['rows'];
 }
コード例 #26
0
ファイル: locum-server.php プロジェクト: aadl/locum
 /**
  * Does the actual import of bib records.  Called by the harvester.
  * It uses start and end parameters because this function can potentially be called by a
  * child process.
  *
  * @param int $start Bib number to start with
  * @param int $end Bib number to end with
  * @return array Array of information about the bibs imported
  */
 public function import_bibs($start, $end, $force = TRUE)
 {
     if (is_callable(array(__CLASS__ . '_hook', __FUNCTION__))) {
         eval('$hook = new ' . __CLASS__ . '_hook;');
         return $hook->{__FUNCTION__}($start, $end);
     }
     $db =& MDB2::connect($this->dsn);
     $couch = new couchClient($this->couchserver, $this->couchdatabase);
     $process_report['skipped'] = 0;
     $process_report['imported'] = 0;
     $utf = "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'";
     $utfprep = $db->query($utf);
     for ($i = $start; $i <= $end; $i++) {
         $sql = "SELECT * FROM locum_bib_items WHERE bnum = {$i}";
         $init_result = $db->query($sql);
         $init_bib_arr = $init_result->fetchAll(MDB2_FETCHMODE_ASSOC);
         try {
             $doc = $couch->getDoc((string) $i);
         } catch (Exception $e) {
             if ($e->getCode() == 404) {
                 // document doesn't exist. create a new one
                 $doc = new stdClass();
                 $doc->_id = (string) $i;
             } else {
                 // something probably wrong with the server. dump out
                 $this->putlog("Problem with CouchDB server for record {$i}. " . $e->getCode());
                 exit(1);
             }
         }
         if ($doc->protected != 1) {
             $bib = $this->locum_cntl->scrape_bib($i, $this->locum_config['api_config']['skip_covers']);
             if ($bib == FALSE || $bib == 'skip' || $bib['suppress'] == 1) {
                 if ($init_bib_arr) {
                     $sql_prep =& $db->prepare('UPDATE locum_bib_items SET active = ? WHERE bnum = ?', array('text', 'integer'));
                     $sql_prep->execute(array('0', $i));
                 }
                 if ($doc->active) {
                     $doc->active = 0;
                     $couch->storeDoc($doc);
                     require_once $this->locum_config['sphinx_config']['api_path'] . '/sphinxapi.php';
                     $cl = new SphinxClient();
                     $cl->SetServer($this->locum_config['sphinx_config']['server_addr'], (int) $this->locum_config['sphinx_config']['server_port']);
                     $cl->UpdateAttributes("bib_items_keyword,bib_items_author,bib_items_title,bib_items_subject,bib_items_callnum,bib_items_tags,bib_items_reviews", array("active"), array($i => array(0)));
                     $this->putlog("suppressed {$i}");
                 }
                 $process_report['skipped']++;
             } else {
                 if ($force || $doc->bib_lastupdate != $bib['bib_lastupdate']) {
                     $subj = $bib['subjects'];
                     $valid_vals = array('bib_created', 'bib_lastupdate', 'bib_prevupdate', 'bib_revs', 'lang', 'loc_code', 'mat_code', 'author', 'addl_author', 'title', 'title_medium', 'addl_title', 'edition', 'series', 'callnum', 'pub_info', 'pub_year', 'stdnum', 'upc', 'lccn', 'descr', 'notes', 'bnum', 'cover_img', 'non_romanized_title', 'non_romanized_author', 'genres', 'non_romanized_notes');
                     foreach ($bib as $bkey => $bval) {
                         if (in_array($bkey, $valid_vals)) {
                             if ($bval) {
                                 $doc->{$bkey} = $bval;
                             }
                             if (is_array($bval)) {
                                 if (count($bval) == 1) {
                                     $bval = $bval[0];
                                 } else {
                                     $bval = serialize($bval);
                                 }
                             }
                             $bib_values[$bkey] = $bval;
                         }
                     }
                     // unset items that are in couch but not mysql for now
                     unset($bib_values['non_romanized_title']);
                     unset($bib_values['non_romanized_author']);
                     unset($bib_values['non_romanized_notes']);
                     unset($bib_values['genres']);
                     if ($init_bib_arr) {
                         $bib_values['cover_img'] = $init_bib_arr[0]['cover_img'];
                     }
                     $bib_values['subjects_ser'] = serialize($subj);
                     $types = array('date', 'date', 'date', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'text', 'text', 'text', 'text', 'text', 'text', 'integer', 'text');
                     $sql_prep = $db->prepare('REPLACE INTO locum_bib_items VALUES (:bnum, :author, :addl_author, :title, :addl_title, :title_medium, :edition, :series, :callnum, :pub_info, :pub_year, :stdnum, :upc, :lccn, :descr, :notes, :subjects_ser, :lang, :loc_code, :mat_code, :cover_img, NOW(), :bib_created, :bib_lastupdate, :bib_prevupdate, :bib_revs, \'1\')');
                     $affrows = $sql_prep->execute($bib_values);
                     $doc->subjects = $subj;
                     $doc->active = 1;
                     if ($doc->upc == '000000000000') {
                         unset($doc->upc);
                     }
                     if (!$bib['pub_year']) {
                         unset($doc->pub_year);
                     }
                     $couch->storeDoc($doc);
                     $this->putlog("Importing bib # {$i} - {$bib['title']}");
                     $sql_prep->free();
                     /*
                               if (is_array($subj) && count($subj)) {
                                 foreach ($subj as $subj_heading) {
                                   $insert_data = array($bib['bnum'], $subj_heading);
                                   $types = array('integer', 'text');
                                   $sql_prep = $db->prepare('INSERT INTO locum_bib_items_subject VALUES (?, ?)', $types, MDB2_PREPARE_MANIP);
                                   $affrows = $sql_prep->execute($insert_data);
                                   $sql_prep->free();
                                 }
                               }
                     */
                     $process_report['imported']++;
                 } else {
                     $process_report['skipped']++;
                     $this->putlog("Skipping unchanged bib # {$i} - {$bib['title']}");
                 }
             }
         }
     }
     $db->disconnect();
     return $process_report;
 }
コード例 #27
0
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
 <?php 
/*$getSQLdata =  mysql_query("SELECT STATUS FROM `log_internet_source` GROUP BY STATUS") or die(mysql_error());
$array_internet = array();
while($rowData = mysql_fetch_array($getSQLdata)){
	array_push($array_internet,$rowData['STATUS']);
}
*/
if (isset($_POST['title'])) {
    global $couchUrl;
    global $facilityId;
    $ttel_resources = new couchClient($couchUrl, "ttel_resources");
    $doc = new stdClass();
    $docType = end(explode(".", $_FILES['uploadedfile']['name']));
    $doc->legacy = array("id" => "", "type" => strtolower($docType));
    $doc->type = $_POST['resType'];
    $doc->kind = 'Resource';
    $doc->language = $_POST['Language'];
    $doc->description = $_POST['discription'];
    $doc->title = $_POST['title'];
    $doc->author = $_POST['author'];
    $doc->created = date('Y-m-d');
    $responce = $ttel_resources->storeDoc($doc);
    print_r($responce);
    try {
        // add attached to document with specified id from response
        $fileName = $responce->id . '.' . end(explode(".", $_FILES['uploadedfile']['name']));
コード例 #28
0
ファイル: convert_const.php プロジェクト: nrjacker4/crm-php
/**
 * 	\file       htdocs/comm/serverprocess.php
 * 	\ingroup    commercial societe
 * 	\brief      load data to display
 */
require_once("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT."/core/class/menubase.class.php");;
$langs->load("companies");
$langs->load("customers");
$langs->load("suppliers");
$langs->load("commercial");
/* Array of database columns which should be read and sent back to DataTables. Use a space where
 * you want to insert a non-database field (for example a counter or static image)
 */

$couchdb = new couchClient("http://"."Administrator:admin@".substr($conf->couchdb->host, 7).':'.$conf->couchdb->port.'/',$conf->couchdb->name);


$flush=0;
if($flush)
{
    // reset old value
    $result = $couchdb->limit(50000)->getView('MenuTop','target_id');
    $i=0;
    
    if(count($result->rows)==0)
    {
        print "Effacement terminé";
        exit;
    }
    
コード例 #29
0
ファイル: update-sphinx-xml.php プロジェクト: aadl/locum
////////////////////////////////////////////////////////////////////////////////
error_reporting(E_ERROR);
$main_time_start = microtime(true);
require_once '../locum-client.php';
$config = parse_ini_file('../config/indexer-xml-config.ini', TRUE);
$process_limit = 1000;
// records to process in each batch
$process_maximum = 1;
// number of processes to spawn
$queue = 'queue:couch-sphinx-xml';
$script_name = $_SERVER['SCRIPT_NAME'];
$log_file = 'sphinx-xml.log';
$pids = array();
$l = new locum();
$couch = new couchClient($l->couchserver, $l->couchdatabase, array('curl' => array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4)));
// Remove current log file and xml docs
unlink($log_file);
exec('rm ../sphinx/xml/*');
// Count records to process
$all_bibs = $couch->limit(0)->getAllDocs();
$record_total = $all_bibs->total_rows;
echo "Processing {$record_total} records in groups of {$process_limit}\n";
// Build the processing queue offsets
$l->redis->del($queue);
$offsets = array();
for ($process_offset = 0; $process_offset < $record_total; $process_offset += $process_limit) {
    $offsets[] = $process_offset;
}
shuffle($offsets);
// randomize order in which offsets are processed
コード例 #30
0
   Get the currently configured Subscriptions
   ----------------------- */
$couch_subscriptions = new couchClient($config->databases->subscriptions->connectionString,
                                       $config->databases->subscriptions->name);
$subscription_results = $couch_subscriptions->getView('views','subscriptions');
if( $subscription_results->total_rows == 0 || empty($subscription_results->rows)){
    echo "No Subscriptions Found. Exiting\n";
    exit(0);
}
$subscriptions = __::pluck($subscription_results->rows, "value");


/* =======================
   Get the currently defined Talking Points
   ----------------------- */
$couch_talkingPoints = new couchClient($config->databases->talkingpoints->connectionString,
                                       $config->databases->talkingpoints->name);
$points_results = $couch_talkingPoints->key(date("m-d-Y"))->getView('views','pointsByDate');
if( $points_results->total_rows == 0 || empty($points_results->rows)){
    echo "No Talking Points Found. Exiting\n";
    exit(0);
}
$points = __::reduce(
            $points_results->rows,
            function($memo, $row){
                $memo[$row->value->handle] = $row->value->points;
                return $memo;
            },array() );

/* =======================
   Configure SubscriptionFulfilment
   ----------------------- */