Exemple #1
0
QVariant RDGetSqlValue(const QString &table,
		       const QString &name1,const QString &test1,
		       const QString &name2,const QString &test2,
                       const QString &name3,const QString &test3,
		       const QString &param,QSqlDatabase *db,bool *valid)
{
  RDSqlQuery *q;
  QString sql;
  QVariant v;

  sql="select `"+param+"` from `"+table+"` where "+
    "(`"+name1+"`=\""+RDEscapeString(test1)+"\")&&"+
    "(`"+name2+"`=\""+RDEscapeString(test1)+"\")&&"+
    "(`"+name3+"`=\""+RDEscapeString(test1)+"\")";
  q=new RDSqlQuery(sql,db);
  if(q->isActive()) {
    q->first();
    v=q->value(0);
    if(valid!=NULL) {
      *valid=!q->isNull(0);
    }
    delete q;
    return v;
  }
  delete q;
  return QVariant();
}
void ListLog::loadButtonData()
{
    QString name=list_log->logName().left(list_log->logName().length()-4);
    QString svcname=list_log->serviceName();

    RDLog *edit_log;
    QString sql;
    RDSqlQuery *q;

    switch(list_logs_dialog->exec(&name,&svcname)) {
    case 0:
        list_log->setLogName(RDLog::tableName(name));
        list_log->load();
        break;

    case 2:
        list_log->save();
        edit_log=new RDLog(list_log->logName().
                           left(list_log->logName().length()-4));
        delete edit_log;
        break;

    case 3:
        sql=QString().sprintf("insert into LOGS set \
                                       NAME=\"%s\",TYPE=0,\
                                       DESCRIPTION=\"%s log\",\
                                       ORIGIN_USER=\"%s\",\
                                       ORIGIN_DATETIME=NOW(),\
                                       LINK_DATETIME=NOW(),\
                                       MODIFIED_DATETIME=NOW(),\
                                       SERVICE=\"%s\"",
                              (const char *)name,
                              (const char *)name,
                              (const char *)rda->ripc()->user(),
                              (const char *)svcname);
        q=new RDSqlQuery(sql);
        if(!q->isActive()) {
            QMessageBox::warning(this,tr("Log Exists"),
                                 tr("Log Already Exists!"));
            delete q;
            return;
        }
        delete q;
        edit_log=new RDLog(name,true);
        RDCreateLogTable(RDLog::tableName(name));
        list_log->setServiceName(svcname);
        list_log->setLogName(RDLog::tableName(name));
        list_log->save();
        edit_log->setModifiedDatetime(QDateTime(QDate::currentDate(),
                                                QTime::currentTime()));
        delete edit_log;
        break;

    case -1:
        list_log->clear();
        break;
    }
}
Exemple #3
0
void AddUser::okData()
{
  RDSqlQuery *q;
  RDSqlQuery *q1;
  QString sql;
  QString username=RDEscapeString(user_name_edit->text());

  if(user_name_edit->text().isEmpty()) {
    QMessageBox::warning(this,tr("Invalid Name"),tr("You must give the user a name!"));
    return;
  }

  sql=QString().sprintf("insert into USERS set LOGIN_NAME=\"%s\",\
                         PASSWORD=PASSWORD(\"\")",
			(const char *)username);
  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    QMessageBox::warning(this,tr("User Exists"),tr("User Already Exists!"),
			 1,0,0);
    delete q;
    return;
  }
  delete q;
  sql="select NAME from GROUPS";
  q=new RDSqlQuery(sql);
  while(q->next()) {
    sql=QString().sprintf("insert into USER_PERMS set USER_NAME=\"%s\",\
                           GROUP_NAME=\"%s\"",
			  (const char *)username,
			  (const char *)q->value(0).toString());
    q1=new RDSqlQuery(sql);
    delete q1;
  }
  delete q;
  EditUser *user=new EditUser(user_name_edit->text(),this,"user");
  if(user->exec()<0) {
    sql=QString().sprintf("delete from USER_PERMS where USER_NAME=\"%s\"",
			  (const char *)username);
    q=new RDSqlQuery(sql);
    delete q;
    sql=QString().sprintf("delete from USERS where LOGIN_NAME=\"%s\"",
			  (const char *)username);
    q=new RDSqlQuery(sql);
    delete q;
    delete user;
    done(-1);
    return;
  }
  delete user;
  *user_name=user_name_edit->text();
  done(0);
}
Exemple #4
0
void MainWidget::addData()
{
  QString logname;
  QString svcname;
  RDSqlQuery *q;
  QString sql;
  std::vector<QString> newlogs;
  RDAddLog *log;

  if(rda->user()->createLog()) {
    log=new RDAddLog(&logname,&svcname,NULL,tr("Add Log"),this);
    if(log->exec()!=0) {
      delete log;
      return;
    }
    delete log;
    sql=QString("insert into LOGS set ")+
      "NAME=\""+RDEscapeString(logname)+"\","+
      "TYPE=0,"+
      "DESCRIPTION=\""+RDEscapeString(logname)+" log\","+
#ifdef WIN32
      "ORIGIN_USER=\""+RDEscapeString(RD_USER_LOGIN_NAME)+"\","+
#else
      "ORIGIN_USER=\""+RDEscapeString(rda->ripc()->user())+"\","+
#endif  // WIN32
      "ORIGIN_DATETIME=now(),"+
      "LINK_DATETIME=now(),"+
      "SERVICE=\""+RDEscapeString(svcname)+"\"";
    q=new RDSqlQuery(sql);
    if(!q->isActive()) {
      QMessageBox::warning(this,tr("Log Exists"),tr("Log Already Exists!"));
      delete q;
      return;
    }
    delete q;
    RDCreateLogTable(RDLog::tableName(logname));
    EditLog *editlog=new EditLog(logname,&log_filter,&log_group,&log_schedcode,
				 &log_clipboard,&newlogs,this);
    editlog->exec();
    delete editlog;
    ListListViewItem *item=new ListListViewItem(log_log_list);
    item->setText(1,logname);
    RefreshItem(item);
    log_log_list->setSelected(item,true);
    log_log_list->ensureItemVisible((Q3ListViewItem *)item);
    for(unsigned i=0;i<newlogs.size();i++) {
      item=new ListListViewItem(log_log_list);
      item->setText(1,newlogs[i]);
      RefreshItem(item);
    }
  }
}
Exemple #5
0
bool RDIsSqlNull(const QString &table,const QString &name,unsigned test,
		 const QString &param,QSqlDatabase *db)
{
  RDSqlQuery *q;
  QString sql;

  sql="select `"+param+"` from `"+table+"` where `"+name+"`="+
    QString().sprintf("%d",test);
  q=new RDSqlQuery(sql,db);
  if(q->isActive()) {
    q->first();
    if(q->isNull(0)) {
      delete q;
      return true;
    }
    else {
      delete q;
      return false;
    }
  }
  delete q;
  return true;
}
Exemple #6
0
bool RDIsSqlNull(const QString &table,const QString &name,const QString &test,
		 const QString &param,QSqlDatabase *db)
{
  RDSqlQuery *q;
  QString sql;

  sql="select `"+param+"` from `"+table+"` where `"+name+"`="+
    "\""+RDEscapeString(test)+"\"";
  q=new RDSqlQuery(sql,db);
  if(q->isActive()) {
    q->first();
    if(q->isNull(0)) {
      delete q;
      return true;
    }
    else {
      delete q;
      return false;
    }
  }
  delete q;
  return true;
}
void AddStation::okData()
{
  RDSqlQuery *q;
  RDSqlQuery *q1;
  QString sql;

  if(add_name_edit->text().isEmpty()) {
    QMessageBox::warning(this,tr("Invalid Name"),
			 tr("You must give the host a name!"));
    return;
  }

  if(add_exemplar_box->currentItem()==0) {  // Create Blank Host Config
    sql=QString().sprintf("insert into STATIONS set NAME=\"%s\",\
                           DESCRIPTION=\"Workstation %s\",USER_NAME=\"user\",\
                           DEFAULT_NAME=\"user\"",
			  (const char *)add_name_edit->text(),
			  (const char *)add_name_edit->text());
    q=new RDSqlQuery(sql);
    if(!q->isActive()) {
      QMessageBox::warning(this,tr("Host Exists"),tr("Host Already Exists!"),
			   1,0,0);
      delete q;
      return;
    }
    delete q;

    //
    // Create Service Perms
    //
    sql="select NAME from SERVICES";
    q=new RDSqlQuery(sql);
    while(q->next()) {
      sql=QString().sprintf("insert into SERVICE_PERMS set\
                           SERVICE_NAME=\"%s\",STATION_NAME=\"%s\"",
			    (const char *)q->value(0).toString(),
			    (const char *)add_name_edit->text());
      q1=new RDSqlQuery(sql);
      delete q1;
    }
    delete q;

    //
    // RDAirPlay/RDPanel Channel Data
    //
    for(unsigned i=0;i<10;i++) {
      sql=QString("insert into RDAIRPLAY_CHANNELS set ")+
	"STATION_NAME=\""+RDEscapeString(add_name_edit->text())+"\","+
	QString().sprintf("INSTANCE=%u",i);
      q=new RDSqlQuery(sql);
      delete q;

      sql=QString("insert into RDPANEL_CHANNELS set ")+
	"STATION_NAME=\""+RDEscapeString(add_name_edit->text())+"\","+
	QString().sprintf("INSTANCE=%u",i);
      q=new RDSqlQuery(sql);
      delete q;
    }
    for(unsigned i=0;i<RD_CUT_EVENT_ID_QUAN;i++) {
      for(unsigned j=0;j<MAX_DECKS;j++) {
	sql=QString("insert into DECK_EVENTS set ")+
	  "STATION_NAME=\""+RDEscapeString(add_name_edit->text())+"\","+
	  QString().sprintf("CHANNEL=%u,",j+129)+
	  QString().sprintf("NUMBER=%u",i+1);
	q=new RDSqlQuery(sql);
	delete q;
      }
    }
  }
int RunLogOperation(int argc,char *argv[],const QString &svcname,
                    int start_offset,bool protect_existing,bool gen_log,
                    bool merge_mus,bool merge_tfc)
{
    QString sql;
    RDSqlQuery *q;
    QString report;
    QString unused_report;
    QString svcname_table=svcname;
    svcname_table.replace(" ","_");

    //
    // Some Basic Structures
    //
#ifndef WIN32
    rda->setUser(rda->station()->defaultName());
#endif  // WIN32
    RDSvc *svc=new RDSvc(svcname);
    if(!svc->exists()) {
        fprintf(stderr,"rdlogmanager: no such service\n");
        return 256;
    }
    QDate start_date=QDate::currentDate().addDays(1+start_offset);
    QString logname=RDDateDecode(svc->nameTemplate(),start_date);
    RDLog *log=new RDLog(logname);

    //
    // Generate Log
    //
    if(gen_log) {
        if(protect_existing&&log->exists()) {
            fprintf(stderr,"log \"%s\" already exists\n",
                    (const char *)log->name().utf8());
            exit(256);
        }
        log->removeTracks(rda->station(),rda->user(),rda->config());
        srand(QTime::currentTime().msec());
        sql=RDCreateStackTableSql(svcname_table);
        q=new RDSqlQuery(sql);
        if(!q->isActive()) {
            fprintf(stderr,"SQL: %s\n",(const char *)sql);
            fprintf(stderr,"SQL Error: %s\n",
                    (const char *)q->lastError().databaseText());
        }
        delete q;
        if(!svc->generateLog(start_date,
                             RDDateDecode(svc->nameTemplate(),start_date),
                             RDDateDecode(svc->nameTemplate(),start_date.addDays(1)),
                             &unused_report)) {
            fprintf(stderr,"rdlogmanager: unable to generate log\n");
            return 256;
        }
        log->updateTracks();

        //
        // Generate Exception Report
        //
        RDLogEvent *event=
            new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
        event->load();
        if((event->validate(&report,start_date)!=0)||
                (!unused_report.isEmpty())) {
            printf("%s\n\n%s",(const char*)report,(const char*)unused_report);
        }
        delete event;
    }

    //
    // Merge Music
    //
    if(merge_mus) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceMusic)==RDLog::LinkDone)) {
            fprintf(stderr,"rdlogmanager: music for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        log->removeTracks(rda->station(),rda->user(),rda->config());
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        svc->clearLogLinks(RDSvc::Music,start_date,logname);
        if(svc->linkLog(RDSvc::Music,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open music schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Music,start_date));
            exit(256);
        }
    }

    //
    // Merge Traffic
    //
    if(merge_tfc) {
        if(!log->exists()) {
            fprintf(stderr,"rdlogmanager: log does not exist\n");
            return 256;
        }
        if(protect_existing&&
                (log->linkState(RDLog::SourceTraffic)==RDLog::LinkDone)) {
            fprintf(stderr,
                    "rdlogmanager: traffic for log \"%s\" is already imported\n",
                    (const char *)log->name().utf8());
            return 256;
        }
        report="";
        svc->clearLogLinks(RDSvc::Traffic,start_date,logname);
        if(svc->linkLog(RDSvc::Traffic,start_date,logname,&report)) {
            printf("%s\n",(const char*)report);
        }
        else {
            fprintf(stderr,
                    "rdlogmanager: unable to open traffic schedule file at \"%s\"\n",
                    (const char *)svc->importFilename(RDSvc::Traffic,start_date));
        }
    }

    //
    // Clean Up
    //
    delete log;
    delete svc;
    return 0;
}
Exemple #9
0
SchedRulesList::SchedRulesList(QString clockname)
{
  QString sql;
  RDSqlQuery *q;
  RDSqlQuery *q1;

  sql=QString().sprintf("create table if not exists `%s_RULES` (\
      CODE varchar(10) not null primary key,\
      MAX_ROW int unsigned,\
      MIN_WAIT int unsigned,\
      NOT_AFTER varchar(10),\
      OR_AFTER varchar(10),\
      OR_AFTER_II varchar(10))",(const char*)clockname.replace(" ","_")); 

  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    printf("SQL: %s\n",(const char *)sql);
    printf("SQL Error: %s\n",(const char *)q->lastError().databaseText());
  }
  delete q;

  sql=QString().sprintf("select CODE,DESCRIPTION from SCHED_CODES order by `CODE` asc"); 

  q=new RDSqlQuery(sql);

  itemcounter=q->size();  
  sched_code = new QString[itemcounter];
  max_row = new int[itemcounter];
  min_wait = new int[itemcounter];
  not_after = new QString[itemcounter];
  or_after = new QString[itemcounter];
  or_after_II = new QString[itemcounter];
  description = new QString[itemcounter];
    
  for (int i=0; i<itemcounter; i++){
    q->next();
    sched_code[i] = q->value(0).toString();
    description[i] = q->value(1).toString();
    sql=QString().sprintf("select MAX_ROW,MIN_WAIT,NOT_AFTER,OR_AFTER,OR_AFTER_II from %s_RULES where CODE=\"%s\"",
	(const char *)clockname.replace(" ","_"),(const char *)sched_code[i]);
    q1=new RDSqlQuery(sql);
    if(q1->first())
      {
      max_row[i] = q1->value(0).toInt();
      min_wait[i] = q1->value(1).toInt();
      not_after[i] = q1->value(2).toString();
      or_after[i] = q1->value(3).toString();
      or_after_II[i] = q1->value(3).toString();
      }
    else
      {
      max_row[i] = 1;
      min_wait[i] = 0;
      not_after[i] = "";
      or_after[i] = "";
      or_after_II[i] = "";
      }
    delete q1;
    }
  delete q;
}
Exemple #10
0
bool RDStation::create(const QString &name)
{
  QString sql;
  RDSqlQuery *q;
  bool ret;
  QString host_name=name;

  //
  // Get our own hostname
  //
  if(host_name.isEmpty()) {
    char stationname[HOST_NAME_MAX+1];
    memset(stationname,0,HOST_NAME_MAX+1);
    if(gethostname(stationname,HOST_NAME_MAX)==0) {
      host_name=stationname;
    }
    else {
      return false;
    }
  }

  sql=QString("insert into STATIONS set ")+
    "NAME=\""+RDEscapeString(host_name)+"\"";
  q=new RDSqlQuery(sql);
  ret=q->isActive();
  delete q;

  for(unsigned i=0;i<10;i++) {
    sql=QString("insert into RDAIRPLAY_CHANNELS set ")+
      "STATION_NAME=\""+RDEscapeString(host_name)+"\","+
      QString().sprintf("INSTANCE=%u",i);
    q=new RDSqlQuery(sql);
    ret=q->isActive();
    delete q;
  }
  for(unsigned i=0;i<10;i++) {
    sql=QString("insert into RDPANEL_CHANNELS set ")+
      "STATION_NAME=\""+RDEscapeString(host_name)+"\","+
      QString().sprintf("INSTANCE=%u",i);
    q=new RDSqlQuery(sql);
    ret=q->isActive();
    delete q;
  }
  for(unsigned i=0;i<3;i++) {
    sql=QString("insert into LOG_MODES set ")+
      "STATION_NAME=\""+RDEscapeString(host_name)+"\","+
      QString().sprintf("MACHINE=%u",i);
    q=new RDSqlQuery(sql);
    ret=q->isActive();
    delete q;
  }
  for(unsigned i=0;i<RD_CUT_EVENT_ID_QUAN;i++) {
    for(unsigned j=0;j<MAX_DECKS;j++) {
      sql=QString("insert into DECK_EVENTS set ")+
	"STATION_NAME=\""+RDEscapeString(host_name)+"\","+
	QString().sprintf("CHANNEL=%u,",j+129)+
	QString().sprintf("NUMBER=%u",i+1);
      q=new RDSqlQuery(sql);
      ret=q->isActive();
      delete q;
    }
  }

  return ret;
}
Exemple #11
0
void GenerateLog::createData()
{
  QString report;
  QString unused_report;
  QString str1;
  QString str2;
  unsigned tracks=0;

  //
  // Generate Log
  //
  RDSvc *svc=new RDSvc(gen_service_box->currentText(),this);
  QString logname=RDDateDecode(svc->nameTemplate(),gen_date_edit->date());
  RDLog *log=new RDLog(logname);
  if(log->exists()) {
    str1=QString(tr("The log for"));
    str2=QString(tr("already exists.  Recreating it\nwill remove any merged Music or Traffic events.\n\nRecreate?"));
    if(QMessageBox::question(this,tr("Log Exists"),
			     QString().sprintf("%s %s %s",(const char *)str1,
		 (const char *)gen_date_edit->date().toString("MM/dd/yyyy"),
					       (const char *)str2),
			     QMessageBox::Yes,QMessageBox::No)!=
       QMessageBox::Yes) {
      delete log;
      delete svc;
      return;
    }
    if((tracks=log->completedTracks())>0) {
      str1=QString(tr("This will also delete the"));
      str2=QString(tr("voice tracks associated with this log.\nContinue?"));
      if(QMessageBox::warning(this,tr("Tracks Exist"),
			      QString().sprintf("%s %u %s",
						(const char *)str1,
						tracks,
						(const char *)str2),
			      QMessageBox::Yes,QMessageBox::No)!=
	 QMessageBox::Yes) {
	delete log;
	delete svc;
	return;
      }
    }
  }
  log->removeTracks(rda->station(),rda->user(),rda->config());

  //
  // Scheduler
  //
  QString sql;
  RDSqlQuery *q;

  srand(QTime::currentTime().msec());
  sql=RDCreateStackTableSql(gen_service_box->currentText().replace(" ","_")); 

  q=new RDSqlQuery(sql);
  if(!q->isActive()) {
    fprintf(stderr,"SQL: %s\n",(const char *)sql);
    fprintf(stderr,"SQL Error: %s\n",
	    (const char *)q->lastError().databaseText());
    delete q;
  }
  delete q;

  connect(svc,SIGNAL(generationProgress(int)),
	  gen_progress_dialog,SLOT(setProgress(int)));
  svc->generateLog(gen_date_edit->date(),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date()),
		   RDDateDecode(svc->nameTemplate(),gen_date_edit->date().
				addDays(1)),&unused_report);
  log->updateTracks();
  delete log;
  delete svc;

  //
  // Generate Exception Report
  //
  RDLogEvent *event=
    new RDLogEvent(QString().sprintf("%s_LOG",(const char *)logname));
  event->load();
  if((event->validate(&report,gen_date_edit->date())==0)&&
     unused_report.isEmpty()) {
    QMessageBox::information(this,tr("No Errors"),tr("No exceptions found."));
  }
  else {
    RDTextFile(report+"\n\n"+unused_report);
  }
  delete event;

  UpdateControls();
}