/**
  * starts a transfer
  *
  * @param $transfer name of the transfer
  * @param $interactive (boolean) : is this a interactive startup with dialog ?
  * @param $enqueue (boolean) : enqueue ?
  */
 function start($transfer, $interactive = false, $enqueue = false)
 {
     global $cfg, $db;
     // set vars
     $this->_setVarsForTransfer($transfer);
     addGrowlMessage($this->client . "-start", $transfer);
     if (!Transmission::isRunning()) {
         $msg = "Transmission RPC not reacheable, cannot start transfer " . $transfer;
         $this->logMessage($this->client . "-start : " . $msg . "\n", true);
         AuditAction($cfg["constants"]["error"], $msg);
         $this->logMessage($msg . "\n", true);
         addGrowlMessage($this->client . "-start", $msg);
         // write error to stat
         $sf = new StatFile($this->transfer, $this->owner);
         $sf->time_left = 'Error: RPC down';
         $sf->write();
         // return
         return false;
     }
     // init properties
     $this->_init($interactive, $enqueue, true, false);
     /*
     if (!is_dir($cfg["path"].'.config/transmissionrpc/torrents')) {
     	if (!is_dir($cfg["path"].'.config'))
     		mkdir($cfg["path"].'.config',0775);
     	
     	if (!is_dir($cfg["path"].'.config/transmissionrpc'))
     		mkdir($cfg["path"].'.config/transmissionrpc',0775);
     	
     	mkdir($cfg["path"].'.config/transmissionrpc/torrents',0775);
     }
     */
     if (!is_dir($cfg['path'] . $cfg['user'])) {
         mkdir($cfg['path'] . $cfg['user'], 0777);
     }
     $this->command = "";
     if (getOwner($transfer) != $cfg['user']) {
         //directory must be changed for different users ?
         changeOwner($transfer, $cfg['user']);
         $this->owner = $cfg['user'];
         // change savepath
         $this->savepath = $cfg["enable_home_dirs"] != 0 ? $cfg['path'] . $this->owner . "/" : $cfg['path'] . $cfg["path_incoming"] . "/";
         $this->command = "re-downloading to " . $this->savepath;
     } else {
         $this->command = "downloading to " . $this->savepath;
     }
     // no client needed
     $this->state = CLIENTHANDLER_STATE_READY;
     // ClientHandler _start()
     $this->_start();
     $hash = getTransferHash($transfer);
     if (empty($hash) || !isTransmissionTransfer($hash)) {
         $hash = addTransmissionTransfer($cfg['uid'], $cfg['transfer_file_path'] . $transfer, $cfg['path'] . $cfg['user']);
         if (is_array($hash) && $hash["result"] == "duplicate torrent") {
             $this->command = 'torrent-add skipped, already exists ' . $transfer;
             //log purpose
             $hash = "";
             $sql = "SELECT hash FROM tf_transfers WHERE transfer = " . $db->qstr($transfer);
             $result = $db->Execute($sql);
             $row = $result->FetchRow();
             if (!empty($row)) {
                 $hash = $row['hash'];
             }
         } else {
             $this->command .= "\n" . 'torrent-add ' . $transfer . ' ' . $hash;
             //log purpose
         }
     } else {
         $this->command .= "\n" . 'torrent-start ' . $transfer . ' ' . $hash;
         //log purpose
     }
     if (!empty($hash)) {
         if ($this->sharekill > 100) {
             // bad sharekill, must be 2.5 for 250%
             $this->sharekill = round((double) $this->sharekill / 100.0, 2);
         }
         $params = array('downloadLimit' => intval($this->drate), 'downloadLimited' => intval($this->drate > 0), 'uploadLimit' => intval($this->rate), 'uploadLimited' => intval($this->rate > 0), 'seedRatioLimit' => (double) $this->sharekill, 'seedRatioMode' => intval($this->sharekill > 0.1));
         $res = (int) startTransmissionTransfer($hash, $enqueue, $params);
     }
     if (!$res) {
         $this->command .= "\n" . $rpc->LastError;
     }
     $this->updateStatFiles($transfer);
     // log (for the torrent stats window)
     $this->logMessage($this->client . "-start : hash={$hash}\ndownload rate=" . $this->drate . ", res={$res}\n", true);
 }
 /**
  * starts a transfer
  *
  * @param $transfer name of the transfer
  * @param $interactive (boolean) : is this a interactive startup with dialog ?
  * @param $enqueue (boolean) : enqueue ?
  */
 function start($transfer, $interactive = false, $enqueue = false)
 {
     global $cfg;
     // set vars
     $this->_setVarsForTransfer($transfer);
     // log
     if ($cfg['debuglevel'] > 0) {
         AuditAction($cfg["constants"]["debug"], $this->client . "-start {$transfer}");
     }
     $this->logMessage($this->client . "-start : " . $transfer . "\n", true);
     $vuze = VuzeRPC::getInstance();
     // do special-pre-start-checks
     if (!VuzeRPC::isRunning()) {
         $msg = "VuzeRPC not reacheable, cannot start transfer " . $transfer;
         AuditAction($cfg["constants"]["error"], $msg);
         $this->logMessage($msg . "\n", true);
         // write error to stat
         $sf = new StatFile($this->transfer, $this->owner);
         $sf->time_left = 'Error: VuzeRPC down';
         $sf->write();
         // return
         return false;
     }
     // init starting of client
     $this->_init($interactive, $enqueue, true, false);
     // only continue if init succeeded (skip start / error)
     if ($this->state != CLIENTHANDLER_STATE_READY) {
         if ($this->state == CLIENTHANDLER_STATE_ERROR) {
             $msg = "Error after init (" . $transfer . "," . $interactive . "," . $enqueue . ",true," . $cfg['enable_sharekill'] . ")";
             array_push($this->messages, $msg);
             $this->logMessage($msg . "\n", true);
         }
         // return
         return false;
     }
     if (getOwner($transfer) != $cfg['user']) {
         //directory must be changed for different users ?
         changeOwner($transfer, $cfg['user']);
         $this->owner = $cfg['user'];
         // change savepath
         $this->savepath = $cfg["enable_home_dirs"] != 0 ? $cfg['path'] . $this->owner . "/" : $cfg['path'] . $cfg["path_incoming"] . "/";
         $this->command = "re-downloading to " . $this->savepath;
     } else {
         $this->command = "downloading to " . $this->savepath;
     }
     // build the command-string
     $content = $cfg['user'] . "\n";
     $content .= $this->savepath . "\n";
     $content .= $this->rate . "\n";
     $content .= $this->drate . "\n";
     $content .= $this->maxuploads . "\n";
     $content .= $this->superseeder . "\n";
     $content .= $this->runtime . "\n";
     $content .= $this->sharekill_param . "\n";
     $content .= $this->minport . "\n";
     $content .= $this->maxport . "\n";
     $content .= $this->maxcons . "\n";
     $content .= $this->rerequest;
     // no client needed
     $this->state = CLIENTHANDLER_STATE_READY;
     // ClientHandler _start()
     $this->_start();
     $hash = getTransferHash($transfer);
     $torrents = $vuze->torrent_get_hashids();
     if (!array_key_exists(strtoupper($hash), $torrents)) {
         $req = $vuze->torrent_add_tf($transfer, $content);
     } else {
         //resume
         $id = $torrents[strtoupper($hash)];
         $req = $vuze->torrent_start(array($id));
     }
     $this->updateStatFiles($transfer);
     return is_object($req) && $req->result == "success";
 }